Class PreboundOptionalBinding<T>

java.lang.Object
javafx.beans.binding.ObjectExpression<T>
javafx.beans.binding.ObjectBinding<T>
com.tobiasdiez.easybind.PreboundBinding<Optional<T>>
com.tobiasdiez.easybind.optional.PreboundOptionalBinding<T>
All Implemented Interfaces:
ObservableOptionalValue<T>, OptionalBinding<T>, javafx.beans.binding.Binding<Optional<T>>, javafx.beans.Observable, javafx.beans.value.ObservableObjectValue<Optional<T>>, javafx.beans.value.ObservableValue<Optional<T>>
Direct Known Subclasses:
OptionalWrapper

public abstract class PreboundOptionalBinding<T> extends PreboundBinding<Optional<T>> implements OptionalBinding<T>
Object binding that binds to its dependencies on creation and unbinds from them on dispose. If one of the registered dependencies becomes invalid, this binding is marked as invalid. To provide a concrete implementation of this class, the method ObjectBinding.computeValue() has to be implemented to calculate the value of this binding based on the current state of the dependencies. This method is called when ObjectBinding.get() is invoked for an invalid binding.
  • Field Summary

    Fields inherited from class com.tobiasdiez.easybind.PreboundBinding

    dependencies
  • Constructor Summary

    Constructors
    Constructor
    Description
    PreboundOptionalBinding(javafx.beans.Observable... dependencies)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    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.
    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.
    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.

    Methods inherited from class com.tobiasdiez.easybind.PreboundBinding

    dispose

    Methods inherited from class javafx.beans.binding.ObjectBinding

    addListener, addListener, allowValidation, bind, computeValue, get, getDependencies, invalidate, isObserved, isValid, onInvalidating, removeListener, removeListener, toString, unbind

    Methods inherited from class javafx.beans.binding.ObjectExpression

    asString, asString, asString, getValue, isEqualTo, isEqualTo, isNotEqualTo, isNotEqualTo, isNotNull, isNull, objectExpression

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

    Methods inherited from interface javafx.beans.binding.Binding

    dispose, getDependencies, invalidate, isValid

    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
  • Constructor Details

    • PreboundOptionalBinding

      public PreboundOptionalBinding(javafx.beans.Observable... dependencies)
  • Method Details

    • mapOpt

      public <U> OptionalBinding<U> mapOpt(Function<? super T,? extends U> mapper)
      Description copied from interface: ObservableOptionalValue
      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.

      Specified by:
      mapOpt in interface ObservableOptionalValue<T>
      Parameters:
      mapper - the mapping to apply to a value, if present
      See Also:
    • flatMapOpt

      public <U> OptionalBinding<U> flatMapOpt(Function<T,Optional<U>> mapper)
      Description copied from interface: ObservableOptionalValue
      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.

      Specified by:
      flatMapOpt in interface ObservableOptionalValue<T>
      Parameters:
      mapper - the mapping to apply to a value, if present
    • orElseOpt

      public EasyBinding<T> orElseOpt(T other)
      Description copied from interface: ObservableOptionalValue
      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.

      Specified by:
      orElseOpt in interface ObservableOptionalValue<T>
    • orElseOpt

      public OptionalBinding<T> orElseOpt(javafx.beans.value.ObservableValue<T> other)
      Description copied from interface: ObservableOptionalValue
      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.

      Specified by:
      orElseOpt in interface ObservableOptionalValue<T>
    • filter

      public OptionalBinding<T> filter(Predicate<? super T> predicate)
      Description copied from interface: ObservableOptionalValue
      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.
      Specified by:
      filter in interface ObservableOptionalValue<T>
      Parameters:
      predicate - the predicate to apply to a value, if present
    • isPresent

      public javafx.beans.binding.BooleanBinding isPresent()
      Description copied from interface: ObservableOptionalValue
      Returns a new observable that holds true if this observable holds value, or false otherwise.
      Specified by:
      isPresent in interface ObservableOptionalValue<T>
    • isEmpty

      public javafx.beans.binding.BooleanBinding isEmpty()
      Description copied from interface: ObservableOptionalValue
      Returns a new observable that holds true if this observable does not hold value, or false otherwise.
      Specified by:
      isEmpty in interface ObservableOptionalValue<T>