Interface ObservableOptionalValue<T>

All Superinterfaces:
javafx.beans.Observable, javafx.beans.value.ObservableObjectValue<Optional<T>>, javafx.beans.value.ObservableValue<Optional<T>>
All Known Subinterfaces:
OptionalBinding<T>
All Known Implementing Classes:
OptionalWrapper, PreboundOptionalBinding

public interface ObservableOptionalValue<T> extends javafx.beans.value.ObservableObjectValue<Optional<T>>
An ObservableValue that may or may not contain values (i.e. an Optional in the category of observable values).
  • Method Summary

    Modifier and Type
    Method
    Description
    Converts this optional observable to an ordinary observable, holding null if this observable does not hold any value.
    filter(Predicate<? super T> predicate)
    Returns a new observable that holds the same value as this observable when the value is present and matches the given predicate, otherwise it holds an empty optional.
    Returns a new observable that holds the result of applying the given function to the value as this observable, if present, otherwise empty.
    default T
    If this observable holds a value, returns the value, otherwise returns other.
    default T
    If this observable holds a value, returns the value, otherwise throws NoSuchElementException.
    default void
    ifValuePresent(Consumer<? super T> action)
    If this observable holds a value, invokes the given function with the value, otherwise does nothing.
    javafx.beans.binding.BooleanBinding
    Returns a new observable that holds true if this observable does not hold value, or false otherwise.
    javafx.beans.binding.BooleanBinding
    Returns a new observable that holds true if this observable holds value, or false otherwise.
    default boolean
    Checks whether this observable has no value.
    default boolean
    Checks whether this observable holds a value.
    default Subscription
    listen(javafx.beans.value.ChangeListener<? super Optional<T>> listener)
     
    default Subscription
    Adds a change listener and returns a Subscription that can be used to remove that listener.
    default <U, O extends javafx.beans.value.ObservableValue<U>>
    OptionalBinding<U>
    mapObservable(Function<? super T,O> mapper)
    Returns a new observable that holds the value of the observable resulting from applying the given function to the value as this observable.
    mapOpt(Function<? super T,? extends U> mapper)
    Returns an ObservableValue that holds the result of applying the given mapping function on this value.
    orElseOpt(javafx.beans.value.ObservableValue<T> other)
    Returns a new observable that holds the value held by this observable, or the value held by other when this observable is empty.
    orElseOpt(T other)
    Returns a new observable that holds the value held by this observable, or other when this observable is empty.
    default <U, O extends javafx.beans.property.Property<U>>
    PropertyBinding<U>
    selectProperty(Function<? super T,O> mapper)
     
    default Subscription
    subscribe(Consumer<? super Optional<T>> listener)
     
    default Subscription
    subscribeToValues(Consumer<? super T> subscriber)
    Invokes the subscriber for the current value, if present, and every new value.

    Methods inherited from interface javafx.beans.Observable

    addListener, removeListener

    Methods inherited from interface javafx.beans.value.ObservableObjectValue

    get

    Methods inherited from interface javafx.beans.value.ObservableValue

    addListener, flatMap, getValue, map, orElse, removeListener, when
  • Method Details

    • isValuePresent

      default boolean isValuePresent()
      Checks whether this observable holds a value.
      Returns:
      true if a value is present, otherwise false
    • isValueEmpty

      default boolean isValueEmpty()
      Checks whether this observable has no value.
      Returns:
      true if a value is not present, otherwise false
    • ifValuePresent

      default void ifValuePresent(Consumer<? super T> action)
      If this observable holds a value, invokes the given function with the value, otherwise does nothing.
      Parameters:
      action - the function to invoke on the value currently held by this observable
    • getValueOrElseThrow

      default T getValueOrElseThrow()
      If this observable holds a value, returns the value, otherwise throws NoSuchElementException.
      Throws:
      NoSuchElementException - if no is value present
    • getValueOrElse

      default T getValueOrElse(T other)
      If this observable holds a value, returns the value, otherwise returns other.
      Parameters:
      other - value to return if there is no value present in this observable
      Returns:
      the value, if present, otherwise other.
    • asOrdinary

      default EasyObservableValue<T> asOrdinary()
      Converts this optional observable to an ordinary observable, holding null if this observable does not hold any value.
      Returns:
      an observable that has the same value as this observable, if present, otherwise null.
    • orElseOpt

      EasyBinding<T> orElseOpt(T other)
      Returns a new observable that holds the value held by this observable, or other when this observable is empty.

      This method is similar to the JavaFX 19 method orElse but recognizes an empty optional instead of null values.

    • orElseOpt

      OptionalBinding<T> orElseOpt(javafx.beans.value.ObservableValue<T> other)
      Returns a new observable that holds the value held by this observable, or the value held by other when this observable is empty.

      This method is similar to the JavaFX 19 method orElse but recognizes an empty optional instead of null values and allows an observable as fallback.

    • filter

      OptionalBinding<T> filter(Predicate<? super T> predicate)
      Returns a new observable that holds the same value as this observable when the value is present and matches the given predicate, otherwise it holds an empty optional.
      Parameters:
      predicate - the predicate to apply to a value, if present
      Throws:
      NullPointerException - if the predicate is null
    • mapOpt

      <U> OptionalBinding<U> mapOpt(Function<? super T,? extends U> mapper)
      Returns an ObservableValue that holds the result of applying the given mapping function on this value. The result is updated when this ObservableOptionalValue changes. If this value is an empty optional, no mapping is applied and the resulting value is also an empty optional. If the function returns null, then this is converted into an empty optional.

      This method is similar to the JavaFX 19 method map but with special handling of empty optionals instead of null values.

      Parameters:
      mapper - the mapping to apply to a value, if present
      See Also:
    • flatMapOpt

      <U> OptionalBinding<U> flatMapOpt(Function<T,Optional<U>> mapper)
      Returns a new observable that holds the result of applying the given function to the value as this observable, if present, otherwise empty.

      This method is similar to ObservableValue.map(Function), but the mapping function is one whose result is already an Optional, and if invoked, flatMap does not wrap it within an additional Optional.

      This method should not be confused with the JavaFX 19 method flatMap which accepts a mapper producing an observable value, and not an Optional.

      Parameters:
      mapper - the mapping to apply to a value, if present
    • mapObservable

      default <U, O extends javafx.beans.value.ObservableValue<U>> OptionalBinding<U> mapObservable(Function<? super T,O> mapper)
      Returns a new observable that holds the value of the observable resulting from applying the given function to the value as this observable. If this observable is empty or the function returns null, then this is converted to an empty optional.
      Parameters:
      mapper - the mapping to apply to a value, if present
      See Also:
    • selectProperty

      default <U, O extends javafx.beans.property.Property<U>> PropertyBinding<U> selectProperty(Function<? super T,O> mapper)
      See Also:
    • isPresent

      javafx.beans.binding.BooleanBinding isPresent()
      Returns a new observable that holds true if this observable holds value, or false otherwise.
    • isEmpty

      javafx.beans.binding.BooleanBinding isEmpty()
      Returns a new observable that holds true if this observable does not hold value, or false otherwise.
    • listenToValues

      default Subscription listenToValues(SimpleChangeListener<? super T> listener)
      Adds a change listener and returns a Subscription that can be used to remove that listener. The listener will only be invoked if the new value is present, use listen(ChangeListener) if you want to be notified about empty values as well.
      See Also:
    • subscribeToValues

      default Subscription subscribeToValues(Consumer<? super T> subscriber)
      Invokes the subscriber for the current value, if present, and every new value. Use subscribe(Consumer) if you want to be notified about empty values as well.
      Parameters:
      subscriber - action to invoke for values of this observable.
      Returns:
      a subscription that can be used to stop invoking subscriber for any further changes.
      See Also:
    • subscribe

      default Subscription subscribe(Consumer<? super Optional<T>> listener)
      See Also:
    • listen

      default Subscription listen(javafx.beans.value.ChangeListener<? super Optional<T>> listener)
      See Also: