1
0
mirror of https://github.com/TeamNewPipe/NewPipe.git synced 2024-11-22 02:53:09 +01:00

Actually there is no need to use flatMap

`null` values returned in the lambda are converted to empty `Optional`s in the `map` method: https://developer.android.com/reference/java/util/Optional#map(java.util.function.Function%3C?%20super%20T,%20?%20extends%20U%3E)
This commit is contained in:
Stypox 2023-01-11 15:26:46 +01:00
parent eed44b3231
commit ad605e2c5a
No known key found for this signature in database
GPG Key ID: 4BDF1B40A49FDD23
3 changed files with 5 additions and 4 deletions

View File

@ -87,6 +87,7 @@ import org.schabi.newpipe.util.urlfinder.UrlFinder;
import org.schabi.newpipe.views.FocusOverlayView;
import java.io.Serializable;
import java.lang.ref.Reference;
import java.lang.ref.WeakReference;
import java.util.ArrayList;
import java.util.Arrays;
@ -748,7 +749,7 @@ public class RouterActivity extends AppCompatActivity {
*/
private Optional<AppCompatActivity> getActivityContext() {
return Optional.ofNullable(weakContext)
.flatMap(context -> Optional.ofNullable(context.get()))
.map(Reference::get)
.filter(context -> !context.isFinishing());
}

View File

@ -1887,7 +1887,7 @@ public final class VideoDetailFragment
setupBrightness();
if (!isPlayerAndPlayerServiceAvailable()
|| player.UIs().get(MainPlayerUi.class).isEmpty()
|| getRoot().flatMap(v -> Optional.ofNullable(v.getParent())).isEmpty()) {
|| getRoot().map(View::getParent).isEmpty()) {
return;
}

View File

@ -62,8 +62,8 @@ public interface MediaItemTag {
@NonNull
static Optional<MediaItemTag> from(@Nullable final MediaItem mediaItem) {
return Optional.ofNullable(mediaItem)
.flatMap(item -> Optional.ofNullable(item.localConfiguration))
.flatMap(localConfiguration -> Optional.ofNullable(localConfiguration.tag))
.map(item -> item.localConfiguration)
.map(localConfiguration -> localConfiguration.tag)
.filter(MediaItemTag.class::isInstance)
.map(MediaItemTag.class::cast);
}