Interface Val<T>

All Superinterfaces:
javafx.beans.Observable, Observable<Consumer<? super T>>, javafx.beans.value.ObservableValue<T>
All Known Subinterfaces:
ProperVal<T>, SuspendableVal<T>, SuspendableVar<T>, Toggle, Var<T>
All Known Implementing Classes:
AnimatedVal, ConstVal, FlatMapped, FlatMappedVal, FlatMappedVar, ListRangeReduction, ListReduction, MappedVal, OrElse, OrElseConst, ProxyVal, SimpleVar, SuspendableBoolean, SuspendableNo, SuspendableValWrapper, SuspendableVarWrapper, SuspendableYes, ToggleFromVal, ValBase, ValWrapper, VarFromVal, VarWrapper

public interface Val<T> extends javafx.beans.value.ObservableValue<T>, Observable<Consumer<? super T>>
Adds more operations to ObservableValue.

Canonical observer of Val<T> is an invalidation observer of type Consumer<? super T>, which accepts the _invalidated_ value. This is different from InvalidationListener, which does not accept the invalidated value.

  • Method Summary

    Modifier and Type
    Method
    Description
    default void
    addInvalidationObserver(Consumer<? super T> observer)
     
    default void
    addListener(javafx.beans.InvalidationListener listener)
     
    default void
    addListener(javafx.beans.value.ChangeListener<? super T> listener)
     
    default Val<T>
    animate(Duration duration, Interpolator<T> interpolator)
    Returns a new Val that gradually transitions to the value of this Val every time this Val changes.
    default Val<T>
    animate(BiFunction<? super T,? super T,Duration> duration, Interpolator<T> interpolator)
    Returns a new Val that gradually transitions to the value of this Val every time this Val changes.
    static <T extends javafx.animation.Interpolatable<T>>
    Val<T>
    animate(javafx.beans.value.ObservableValue<T> obs, Duration duration)
    Like animate(ObservableValue, Duration, Interpolator), but uses the interpolation defined by the Interpolatable type T.
    static <T> Val<T>
    animate(javafx.beans.value.ObservableValue<T> obs, Duration duration, Interpolator<T> interpolator)
    Creates a new Val that gradually transitions to the value of the given ObservableValue obs every time obs changes.
    static <T extends javafx.animation.Interpolatable<T>>
    Val<T>
    animate(javafx.beans.value.ObservableValue<T> obs, BiFunction<? super T,? super T,Duration> duration)
    Like animate(ObservableValue, BiFunction, Interpolator), but uses the interpolation defined by the Interpolatable type T.
    static <T> Val<T>
    animate(javafx.beans.value.ObservableValue<T> obs, BiFunction<? super T,? super T,Duration> duration, Interpolator<T> interpolator)
    Creates a new Val that gradually transitions to the value of the given ObservableValue obs every time obs changes.
    default LiveList<T>
    Returns a LiveList view of this Val.
    default Var<T>
    asVar(Consumer<T> setValue)
    Let's this Val be viewed as a Var, with the given setValue function serving the purpose of WritableValue.setValue(Object).
    default EventStream<Change<T>>
    Returns a stream of changed values, which emits the changed value (i.e.
    static <A, B, R> Val<R>
    combine(javafx.beans.value.ObservableValue<A> src1, javafx.beans.value.ObservableValue<B> src2, BiFunction<? super A,? super B,? extends R> f)
     
    static <A, B, C, D, E, F, R>
    Val<R>
    combine(javafx.beans.value.ObservableValue<A> src1, javafx.beans.value.ObservableValue<B> src2, javafx.beans.value.ObservableValue<C> src3, javafx.beans.value.ObservableValue<D> src4, javafx.beans.value.ObservableValue<E> src5, javafx.beans.value.ObservableValue<F> src6, HexaFunction<? super A,? super B,? super C,? super D,? super E,? super F,? extends R> f)
     
    static <A, B, C, D, E, R>
    Val<R>
    combine(javafx.beans.value.ObservableValue<A> src1, javafx.beans.value.ObservableValue<B> src2, javafx.beans.value.ObservableValue<C> src3, javafx.beans.value.ObservableValue<D> src4, javafx.beans.value.ObservableValue<E> src5, PentaFunction<? super A,? super B,? super C,? super D,? super E,? extends R> f)
     
    static <A, B, C, D, R>
    Val<R>
    combine(javafx.beans.value.ObservableValue<A> src1, javafx.beans.value.ObservableValue<B> src2, javafx.beans.value.ObservableValue<C> src3, javafx.beans.value.ObservableValue<D> src4, TetraFunction<? super A,? super B,? super C,? super D,? extends R> f)
     
    static <A, B, C, R>
    Val<R>
    combine(javafx.beans.value.ObservableValue<A> src1, javafx.beans.value.ObservableValue<B> src2, javafx.beans.value.ObservableValue<C> src3, TriFunction<? super A,? super B,? super C,? extends R> f)
     
    default Val<T>
    conditionOn(javafx.beans.value.ObservableValue<Boolean> condition)
    Returns a new Val that only observes this Val when condition is true.
    static <T> Val<T>
    conditionOn(javafx.beans.value.ObservableValue<T> obs, javafx.beans.value.ObservableValue<Boolean> condition)
     
    static <T> Val<T>
    conditionOnShowing(javafx.beans.value.ObservableValue<T> obs, javafx.scene.Node node)
     
    default Val<T>
    conditionOnShowing(javafx.scene.Node node)
    Equivalent to conditionOn(ObservableValue) where the condition is that node is showing: it is part of a scene graph (Node.sceneProperty() is not null), its scene is part of a window (Scene.windowProperty() is not null) and the window is showing (Window.showingProperty() is true).
    static <T> Val<T>
    constant(T value)
    Returns a constant Val that holds the given value.
    static <T> Val<T>
    create(Supplier<? extends T> computeValue, javafx.beans.Observable... dependencies)
     
    static <T> Val<T>
    create(Supplier<? extends T> computeValue, EventStream<?> invalidations)
     
    default Val<T>
    filter(Predicate<? super T> p)
    Returns a new Val that holds the same value as this Val when the value satisfies the predicate and is empty when this Val is empty or its value does not satisfy the given predicate.
    static <T> Val<T>
    filter(javafx.beans.value.ObservableValue<T> src, Predicate<? super T> p)
     
    default <U> Val<U>
    flatMap(Function<? super T,? extends javafx.beans.value.ObservableValue<U>> f)
    Returns a new Val that, when this Val holds value x, holds the value held by f(x), and is empty when this Val is empty.
    static <T, U> Val<U>
    flatMap(javafx.beans.value.ObservableValue<T> src, Function<? super T,? extends javafx.beans.value.ObservableValue<U>> f)
     
    default Optional<T>
    Returns an Optional describing the value currently held by this Val, or and empty Optional if this Val is empty.
    default T
    getOrElse(T defaultValue)
    Returns the value currently held by this Val.
    default T
    getOrSupply(Supplier<? extends T> defaultSupplier)
    Like getOrElse(Object), except the default value is computed by defaultSupplier only when necessary.
    default T
    Returns the value currently held by this Val.
    default void
    ifPresent(Consumer<? super T> f)
    Invokes the given function if this Val holds a (non-null) value.
    default EventStream<T>
    Returns a stream of invalidated values, which emits the invalidated value (i.e.
    default boolean
    Inverse of isPresent().
    default boolean
    Checks whether this Val holds a (non-null) value.
    default <U> Val<U>
    map(Function<? super T,? extends U> f)
    Returns a new Val that holds a mapping of the value held by this Val, and is empty when this Val is empty.
    static <T, U> Val<U>
    map(javafx.beans.value.ObservableValue<T> src, Function<? super T,? extends U> f)
     
    default <U> Val<U>
    mapDynamic(javafx.beans.value.ObservableValue<? extends Function<? super T,? extends U>> f)
    Like map(Function), but also allows dynamically changing map function.
    static <T, U> Val<U>
    mapDynamic(javafx.beans.value.ObservableValue<T> src, javafx.beans.value.ObservableValue<? extends Function<? super T,? extends U>> f)
     
    default Subscription
    observeChanges(javafx.beans.value.ChangeListener<? super T> listener)
    Adds a change listener and returns a Subscription that can be used to remove that listener.
    static <T> Subscription
    observeChanges(javafx.beans.value.ObservableValue<? extends T> obs, javafx.beans.value.ChangeListener<? super T> listener)
     
    default Subscription
    observeInvalidations(Consumer<? super T> oldValueObserver)
     
    observeInvalidations(javafx.beans.value.ObservableValue<?> obs, javafx.beans.InvalidationListener listener)
     
    static <T> Val<T>
    orElse(javafx.beans.value.ObservableValue<? extends T> src, javafx.beans.value.ObservableValue<? extends T> other)
     
    default Val<T>
    orElse(javafx.beans.value.ObservableValue<T> other)
    Returns a new Val that holds the value held by this Val, or the value held by other when this Val is empty.
    static <T> Val<T>
    orElseConst(javafx.beans.value.ObservableValue<? extends T> src, T other)
     
    default Val<T>
    orElseConst(T other)
    Returns a new Val that holds the value held by this Val, or other when this Val is empty.
    default Subscription
    pin()
     
    default void
     
    default void
    removeListener(javafx.beans.InvalidationListener listener)
     
    default void
    removeListener(javafx.beans.value.ChangeListener<? super T> listener)
     
    default <U> Var<U>
    selectVar(Function<? super T,? extends javafx.beans.property.Property<U>> f)
    Similar to flatMap(Function), except the returned Val is also a Var.
    default <U> Var<U>
    selectVar(Function<? super T,? extends javafx.beans.property.Property<U>> f, U resetToOnUnbind)
     
    static <T, U> Var<U>
    selectVar(javafx.beans.value.ObservableValue<T> src, Function<? super T,? extends javafx.beans.property.Property<U>> f)
     
    static <T, U> Var<U>
    selectVar(javafx.beans.value.ObservableValue<T> src, Function<? super T,? extends javafx.beans.property.Property<U>> f, U resetToOnUnbind)
     
    static Val<Boolean>
    showingProperty(javafx.scene.Node node)
    Returns a Val whose value is true when node is showing: it is part of a scene graph (Node.sceneProperty() is not null), its scene is part of a window (Scene.windowProperty() is not null) and the window is showing (Window.showingProperty() is true).
    default SuspendableVal<T>
     
    static <T> SuspendableVal<T>
    suspendable(javafx.beans.value.ObservableValue<T> obs)
     
    default EventStream<T>
    Returns a stream of values of this Val.
    static <T> Val<T>
    wrap(javafx.beans.value.ObservableValue<T> obs)
    Returns a Val wrapper around ObservableValue.

    Methods inherited from interface org.reactfx.Observable

    addObserver, observe, removeObserver

    Methods inherited from interface javafx.beans.value.ObservableValue

    getValue
  • Method Details

    • addInvalidationObserver

      default void addInvalidationObserver(Consumer<? super T> observer)
    • removeInvalidationObserver

      default void removeInvalidationObserver(Consumer<? super T> observer)
    • observeInvalidations

      default Subscription observeInvalidations(Consumer<? super T> oldValueObserver)
    • pin

      default Subscription pin()
    • addListener

      default void addListener(javafx.beans.InvalidationListener listener)
      Specified by:
      addListener in interface javafx.beans.Observable
    • removeListener

      default void removeListener(javafx.beans.InvalidationListener listener)
      Specified by:
      removeListener in interface javafx.beans.Observable
    • addListener

      default void addListener(javafx.beans.value.ChangeListener<? super T> listener)
      Specified by:
      addListener in interface javafx.beans.value.ObservableValue<T>
    • removeListener

      default void removeListener(javafx.beans.value.ChangeListener<? super T> listener)
      Specified by:
      removeListener in interface javafx.beans.value.ObservableValue<T>
    • observeChanges

      default Subscription observeChanges(javafx.beans.value.ChangeListener<? super T> listener)
      Adds a change listener and returns a Subscription that can be used to remove that listener.
    • invalidations

      default EventStream<T> invalidations()
      Returns a stream of invalidated values, which emits the invalidated value (i.e. the old value) on each invalidation of this observable value.
    • changes

      default EventStream<Change<T>> changes()
      Returns a stream of changed values, which emits the changed value (i.e. the old and the new value) on each change of this observable value.
    • values

      default EventStream<T> values()
      Returns a stream of values of this Val. The returned stream emits the current value of this Val for each new subscriber and then the new value whenever the value changes.
    • isPresent

      default boolean isPresent()
      Checks whether this Val holds a (non-null) value.
      Returns:
      true if this Val holds a (non-null) value, false otherwise.
    • isEmpty

      default boolean isEmpty()
      Inverse of isPresent().
    • ifPresent

      default void ifPresent(Consumer<? super T> f)
      Invokes the given function if this Val holds a (non-null) value.
      Parameters:
      f - function to invoke on the value currently held by this Val.
    • getOrThrow

      default T getOrThrow()
      Returns the value currently held by this Val.
      Throws:
      NoSuchElementException - if there is no value present.
    • getOrElse

      default T getOrElse(T defaultValue)
      Returns the value currently held by this Val. If this Val is empty, defaultValue is returned instead.
      Parameters:
      defaultValue - value to return if there is no value present in this Val.
    • getOrSupply

      default T getOrSupply(Supplier<? extends T> defaultSupplier)
      Like getOrElse(Object), except the default value is computed by defaultSupplier only when necessary.
      Parameters:
      defaultSupplier - computation to produce default value, if this Val is empty.
    • getOpt

      default Optional<T> getOpt()
      Returns an Optional describing the value currently held by this Val, or and empty Optional if this Val is empty.
    • orElseConst

      default Val<T> orElseConst(T other)
      Returns a new Val that holds the value held by this Val, or other when this Val is empty.
    • orElse

      default Val<T> orElse(javafx.beans.value.ObservableValue<T> other)
      Returns a new Val that holds the value held by this Val, or the value held by other when this Val is empty.
    • filter

      default Val<T> filter(Predicate<? super T> p)
      Returns a new Val that holds the same value as this Val when the value satisfies the predicate and is empty when this Val is empty or its value does not satisfy the given predicate.
    • map

      default <U> Val<U> map(Function<? super T,? extends U> f)
      Returns a new Val that holds a mapping of the value held by this Val, and is empty when this Val is empty.
      Parameters:
      f - function to map the value held by this Val.
    • mapDynamic

      default <U> Val<U> mapDynamic(javafx.beans.value.ObservableValue<? extends Function<? super T,? extends U>> f)
      Like map(Function), but also allows dynamically changing map function.
    • flatMap

      default <U> Val<U> flatMap(Function<? super T,? extends javafx.beans.value.ObservableValue<U>> f)
      Returns a new Val that, when this Val holds value x, holds the value held by f(x), and is empty when this Val is empty.
    • selectVar

      default <U> Var<U> selectVar(Function<? super T,? extends javafx.beans.property.Property<U>> f)
      Similar to flatMap(Function), except the returned Val is also a Var. This means you can call setValue() and bind() methods on the returned value, which delegate to the currently selected Property.

      As the value of this Val changes, so does the selected Property. When the Var returned from this method is bound, as the selected Property changes, the previously selected Property is unbound and the newly selected Property is bound.

      Note that if the currently selected Property is null, then calling getValue() on the returned value will return null regardless of any prior call to setValue() or bind().

    • selectVar

      default <U> Var<U> selectVar(Function<? super T,? extends javafx.beans.property.Property<U>> f, U resetToOnUnbind)
    • conditionOn

      default Val<T> conditionOn(javafx.beans.value.ObservableValue<Boolean> condition)
      Returns a new Val that only observes this Val when condition is true. More precisely, the returned Val observes condition whenever it itself has at least one observer and observes this Val whenever it itself has at least one observer and the value of condition is true. When condition is true, the returned Val has the same value as this Val. When condition is false, the returned Val has the value that was held by this Val at the time when condition changed to false.
    • conditionOnShowing

      default Val<T> conditionOnShowing(javafx.scene.Node node)
      Equivalent to conditionOn(ObservableValue) where the condition is that node is showing: it is part of a scene graph (Node.sceneProperty() is not null), its scene is part of a window (Scene.windowProperty() is not null) and the window is showing (Window.showingProperty() is true).
    • suspendable

      default SuspendableVal<T> suspendable()
    • animate

      default Val<T> animate(BiFunction<? super T,? super T,Duration> duration, Interpolator<T> interpolator)
      Returns a new Val that gradually transitions to the value of this Val every time this Val changes.

      When the returned Val has no observer, there is no gradual transition taking place. This means that there is no animation running in the background that would consume system resources. This also means that in that case ObservableValue.getValue() always returns the target value (i.e. the current value of this Val), instead of any intermediate interpolated value.

      Parameters:
      duration - function that calculates the desired duration of the transition for two boundary values.
      interpolator - calculates the interpolated value between two boundary values, given a fraction.
    • animate

      default Val<T> animate(Duration duration, Interpolator<T> interpolator)
      Returns a new Val that gradually transitions to the value of this Val every time this Val changes.

      When the returned Val has no observer, there is no gradual transition taking place. This means that there is no animation running in the background that would consume system resources. This also means that in that case ObservableValue.getValue() always returns the target value (i.e. the current value of this Val), instead of any intermediate interpolated value.

      Parameters:
      duration - the desired duration of the transition
      interpolator - calculates the interpolated value between two boundary values, given a fraction.
    • asVar

      default Var<T> asVar(Consumer<T> setValue)
      Let's this Val be viewed as a Var, with the given setValue function serving the purpose of WritableValue.setValue(Object).
      See Also:
    • asList

      default LiveList<T> asList()
      Returns a LiveList view of this Val. The returned list will have size 1 when this Val is present (i.e. not null) and size 0 otherwise.
    • wrap

      static <T> Val<T> wrap(javafx.beans.value.ObservableValue<T> obs)
      Returns a Val wrapper around ObservableValue. If the argument is already a Val<T>, no wrapping occurs and the argument is returned as is. Note that one rarely needs to use this method, because most of the time one can use the appropriate static method directly to get the desired result. For example, instead of
       
       Val.wrap(obs).orElse(other)
       
       
      one can write
       
       Val.orElse(obs, other)
       
       
      However, an explicit wrapper is necessary if access to observeInvalidations(Consumer), or invalidations() is needed, since there is no direct static method equivalent for them.
    • observeChanges

      static <T> Subscription observeChanges(javafx.beans.value.ObservableValue<? extends T> obs, javafx.beans.value.ChangeListener<? super T> listener)
    • observeInvalidations

      static Subscription observeInvalidations(javafx.beans.value.ObservableValue<?> obs, javafx.beans.InvalidationListener listener)
    • orElseConst

      static <T> Val<T> orElseConst(javafx.beans.value.ObservableValue<? extends T> src, T other)
    • orElse

      static <T> Val<T> orElse(javafx.beans.value.ObservableValue<? extends T> src, javafx.beans.value.ObservableValue<? extends T> other)
    • filter

      static <T> Val<T> filter(javafx.beans.value.ObservableValue<T> src, Predicate<? super T> p)
    • map

      static <T, U> Val<U> map(javafx.beans.value.ObservableValue<T> src, Function<? super T,? extends U> f)
    • mapDynamic

      static <T, U> Val<U> mapDynamic(javafx.beans.value.ObservableValue<T> src, javafx.beans.value.ObservableValue<? extends Function<? super T,? extends U>> f)
    • flatMap

      static <T, U> Val<U> flatMap(javafx.beans.value.ObservableValue<T> src, Function<? super T,? extends javafx.beans.value.ObservableValue<U>> f)
    • selectVar

      static <T, U> Var<U> selectVar(javafx.beans.value.ObservableValue<T> src, Function<? super T,? extends javafx.beans.property.Property<U>> f)
    • selectVar

      static <T, U> Var<U> selectVar(javafx.beans.value.ObservableValue<T> src, Function<? super T,? extends javafx.beans.property.Property<U>> f, U resetToOnUnbind)
    • conditionOn

      static <T> Val<T> conditionOn(javafx.beans.value.ObservableValue<T> obs, javafx.beans.value.ObservableValue<Boolean> condition)
    • conditionOnShowing

      static <T> Val<T> conditionOnShowing(javafx.beans.value.ObservableValue<T> obs, javafx.scene.Node node)
    • suspendable

      static <T> SuspendableVal<T> suspendable(javafx.beans.value.ObservableValue<T> obs)
    • animate

      static <T> Val<T> animate(javafx.beans.value.ObservableValue<T> obs, BiFunction<? super T,? super T,Duration> duration, Interpolator<T> interpolator)
      Creates a new Val that gradually transitions to the value of the given ObservableValue obs every time obs changes.

      When the returned Val has no observer, there is no gradual transition taking place. This means that there is no animation running in the background that would consume system resources. This also means that in that case ObservableValue.getValue() always returns the target value (i.e. the current value of obs), instead of any intermediate interpolated value.

      Parameters:
      obs - observable value to animate
      duration - function that calculates the desired duration of the transition for two boundary values.
      interpolator - calculates the interpolated value between two boundary values, given a fraction.
    • animate

      static <T> Val<T> animate(javafx.beans.value.ObservableValue<T> obs, Duration duration, Interpolator<T> interpolator)
      Creates a new Val that gradually transitions to the value of the given ObservableValue obs every time obs changes.

      When the returned Val has no observer, there is no gradual transition taking place. This means that there is no animation running in the background that would consume system resources. This also means that in that case ObservableValue.getValue() always returns the target value (i.e. the current value of obs), instead of any intermediate interpolated value.

      Parameters:
      obs - observable value to animate
      duration - the desired duration of the transition
      interpolator - calculates the interpolated value between two boundary values, given a fraction.
    • animate

      static <T extends javafx.animation.Interpolatable<T>> Val<T> animate(javafx.beans.value.ObservableValue<T> obs, BiFunction<? super T,? super T,Duration> duration)
      Like animate(ObservableValue, BiFunction, Interpolator), but uses the interpolation defined by the Interpolatable type T.
    • animate

      static <T extends javafx.animation.Interpolatable<T>> Val<T> animate(javafx.beans.value.ObservableValue<T> obs, Duration duration)
      Like animate(ObservableValue, Duration, Interpolator), but uses the interpolation defined by the Interpolatable type T.
    • combine

      static <A, B, R> Val<R> combine(javafx.beans.value.ObservableValue<A> src1, javafx.beans.value.ObservableValue<B> src2, BiFunction<? super A,? super B,? extends R> f)
    • combine

      static <A, B, C, R> Val<R> combine(javafx.beans.value.ObservableValue<A> src1, javafx.beans.value.ObservableValue<B> src2, javafx.beans.value.ObservableValue<C> src3, TriFunction<? super A,? super B,? super C,? extends R> f)
    • combine

      static <A, B, C, D, R> Val<R> combine(javafx.beans.value.ObservableValue<A> src1, javafx.beans.value.ObservableValue<B> src2, javafx.beans.value.ObservableValue<C> src3, javafx.beans.value.ObservableValue<D> src4, TetraFunction<? super A,? super B,? super C,? super D,? extends R> f)
    • combine

      static <A, B, C, D, E, R> Val<R> combine(javafx.beans.value.ObservableValue<A> src1, javafx.beans.value.ObservableValue<B> src2, javafx.beans.value.ObservableValue<C> src3, javafx.beans.value.ObservableValue<D> src4, javafx.beans.value.ObservableValue<E> src5, PentaFunction<? super A,? super B,? super C,? super D,? super E,? extends R> f)
    • combine

      static <A, B, C, D, E, F, R> Val<R> combine(javafx.beans.value.ObservableValue<A> src1, javafx.beans.value.ObservableValue<B> src2, javafx.beans.value.ObservableValue<C> src3, javafx.beans.value.ObservableValue<D> src4, javafx.beans.value.ObservableValue<E> src5, javafx.beans.value.ObservableValue<F> src6, HexaFunction<? super A,? super B,? super C,? super D,? super E,? super F,? extends R> f)
    • create

      static <T> Val<T> create(Supplier<? extends T> computeValue, javafx.beans.Observable... dependencies)
    • create

      static <T> Val<T> create(Supplier<? extends T> computeValue, EventStream<?> invalidations)
    • constant

      static <T> Val<T> constant(T value)
      Returns a constant Val that holds the given value. The value never changes and no notifications are ever produced.
    • showingProperty

      static Val<Boolean> showingProperty(javafx.scene.Node node)
      Returns a Val whose value is true when node is showing: it is part of a scene graph (Node.sceneProperty() is not null), its scene is part of a window (Scene.windowProperty() is not null) and the window is showing (Window.showingProperty() is true).