Use Optional chaining.

This commit is contained in:
Isira Seneviratne 2022-11-03 06:00:51 +05:30
parent cae0eda806
commit af75d5a055
6 changed files with 53 additions and 64 deletions

View file

@ -2423,23 +2423,20 @@ public final class VideoDetailFragment
// helpers to check the state of player and playerService
boolean isPlayerAvailable() {
return (player != null);
return player != null;
}
boolean isPlayerServiceAvailable() {
return (playerService != null);
return playerService != null;
}
boolean isPlayerAndPlayerServiceAvailable() {
return (player != null && playerService != null);
return player != null && playerService != null;
}
public Optional<View> getRoot() {
if (player == null) {
return Optional.empty();
}
return player.UIs().get(VideoPlayerUi.class)
return Optional.ofNullable(player)
.flatMap(player1 -> player1.UIs().get(VideoPlayerUi.class))
.map(playerUi -> playerUi.getBinding().getRoot());
}