Class Optional<T>

java.lang.Object
com.brightcove.player.data.Optional<T>
Type Parameters:
T - the expected type of the nullable value.

public class Optional<T> extends Object
Optional wrapper can be to pass nullable value safely through RxJava2 stream. Though Android supports this construct since API level 24, using it is not viable because the SDK has to support lower API levels.
  • Constructor Details

    • Optional

      public Optional(@Nullable T value)
      Constructs a new optional value
      Parameters:
      value - the optional value
  • Method Details

    • from

      public static <T> Optional<T> from(T value)
    • isPresent

      public boolean isPresent()
      Checks if a non-null value is present.
      Returns:
      true if there is a value present, otherwise false.
    • get

      @NonNull public T get()
      Gets the optional value if present.
      Returns:
      reference to the optional value.
      Throws:
      NoSuchElementException - if the value is null.
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object
    • equals

      public boolean equals(Object rhs)
      Overrides:
      equals in class Object
    • empty

      public static <T> Optional<T> empty()
      Returns an empty Optional instance. No value is present for this Optional.
      Type Parameters:
      T - Type of the optional value
      Returns:
      an empty Optional