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
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 TypeMethodDescriptiondefault void
addInvalidationObserver
(Consumer<? super T> observer) default void
addListener
(javafx.beans.InvalidationListener listener) default void
addListener
(javafx.beans.value.ChangeListener<? super T> listener) animate
(Duration duration, Interpolator<T> interpolator) animate
(BiFunction<? super T, ? super T, Duration> duration, Interpolator<T> interpolator) static <T extends javafx.animation.Interpolatable<T>>
Val<T> Likeanimate(ObservableValue, Duration, Interpolator)
, but uses the interpolation defined by the Interpolatable typeT
.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 ObservableValueobs
every timeobs
changes.static <T extends javafx.animation.Interpolatable<T>>
Val<T> animate
(javafx.beans.value.ObservableValue<T> obs, BiFunction<? super T, ? super T, Duration> duration) Likeanimate(ObservableValue, BiFunction, Interpolator)
, but uses the interpolation defined by the Interpolatable typeT
.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 ObservableValueobs
every timeobs
changes.asList()
default EventStream
<Change<T>> changes()
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) conditionOn
(javafx.beans.value.ObservableValue<Boolean> condition) 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) conditionOnShowing
(javafx.scene.Node node) Equivalent toconditionOn(ObservableValue)
where the condition is thatnode
is showing: it is part of a scene graph (Node.sceneProperty()
is notnull
), its scene is part of a window (Scene.windowProperty()
is notnull
) and the window is showing (Window.showingProperty()
istrue
).static <T> Val
<T> constant
(T value) Returns a constant Val that holds the given value.static <T> Val
<T> static <T> Val
<T> create
(Supplier<? extends T> computeValue, EventStream<?> invalidations) static <T> Val
<T> default <U> Val
<U> static <T,
U> Val <U> flatMap
(javafx.beans.value.ObservableValue<T> src, Function<? super T, ? extends javafx.beans.value.ObservableValue<U>> f) getOpt()
default T
Returns the value currently held by this Val.default T
getOrSupply
(Supplier<? extends T> defaultSupplier) LikegetOrElse(Object)
, except the default value is computed bydefaultSupplier
only when necessary.default T
Returns the value currently held by this Val.default void
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
isEmpty()
Inverse ofisPresent()
.default boolean
Checks whether this Val holds a (non-null) value.default <U> Val
<U> static <T,
U> Val <U> default <U> Val
<U> mapDynamic
(javafx.beans.value.ObservableValue<? extends Function<? super T, ? extends U>> f) Likemap(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) static Subscription
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) static <T> Val
<T> orElseConst
(javafx.beans.value.ObservableValue<? extends T> src, T other) orElseConst
(T other) default Subscription
pin()
default void
removeInvalidationObserver
(Consumer<? super T> observer) default void
removeListener
(javafx.beans.InvalidationListener listener) default void
removeListener
(javafx.beans.value.ChangeListener<? super T> listener) default <U> Var
<U> Similar toflatMap(Function)
, except the returned Val is also a Var.default <U> Var
<U> 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) showingProperty
(javafx.scene.Node node) Returns a Val whose value istrue
whennode
is showing: it is part of a scene graph (Node.sceneProperty()
is notnull
), its scene is part of a window (Scene.windowProperty()
is notnull
) and the window is showing (Window.showingProperty()
istrue
).default SuspendableVal
<T> static <T> SuspendableVal
<T> suspendable
(javafx.beans.value.ObservableValue<T> obs) default EventStream
<T> values()
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
-
removeInvalidationObserver
-
observeInvalidations
-
pin
-
addListener
default void addListener(javafx.beans.InvalidationListener listener) - Specified by:
addListener
in interfacejavafx.beans.Observable
-
removeListener
default void removeListener(javafx.beans.InvalidationListener listener) - Specified by:
removeListener
in interfacejavafx.beans.Observable
-
addListener
- Specified by:
addListener
in interfacejavafx.beans.value.ObservableValue<T>
-
removeListener
- Specified by:
removeListener
in interfacejavafx.beans.value.ObservableValue<T>
-
observeChanges
Adds a change listener and returns a Subscription that can be used to remove that listener. -
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
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
-
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 ofisPresent()
. -
ifPresent
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
Returns the value currently held by this Val.- Throws:
NoSuchElementException
- if there is no value present.
-
getOrElse
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
LikegetOrElse(Object)
, except the default value is computed bydefaultSupplier
only when necessary.- Parameters:
defaultSupplier
- computation to produce default value, if this Val is empty.
-
getOpt
-
orElseConst
-
orElse
-
filter
-
map
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) Likemap(Function)
, but also allows dynamically changing map function. -
flatMap
-
selectVar
Similar toflatMap(Function)
, except the returned Val is also a Var. This means you can callsetValue()
andbind()
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 callinggetValue()
on the returned value will returnnull
regardless of any prior call tosetValue()
orbind()
. -
selectVar
-
conditionOn
Returns a new Val that only observes this Val whencondition
istrue
. More precisely, the returned Val observescondition
whenever it itself has at least one observer and observesthis
Val whenever it itself has at least one observer and the value ofcondition
istrue
. Whencondition
istrue
, the returned Val has the same value as this Val. Whencondition
isfalse
, the returned Val has the value that was held by this Val at the time whencondition
changed tofalse
. -
conditionOnShowing
Equivalent toconditionOn(ObservableValue)
where the condition is thatnode
is showing: it is part of a scene graph (Node.sceneProperty()
is notnull
), its scene is part of a window (Scene.windowProperty()
is notnull
) and the window is showing (Window.showingProperty()
istrue
). -
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
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 transitioninterpolator
- calculates the interpolated value between two boundary values, given a fraction.
-
asVar
Let's this Val be viewed as a Var, with the givensetValue
function serving the purpose ofWritableValue.setValue(Object)
.- See Also:
-
asList
-
wrap
Returns a Val wrapper around ObservableValue. If the argument is already aVal<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 ofVal.wrap(obs).orElse(other)
Val.orElse(obs, other)
observeInvalidations(Consumer)
, orinvalidations()
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
-
orElse
static <T> Val<T> orElse(javafx.beans.value.ObservableValue<? extends T> src, javafx.beans.value.ObservableValue<? extends T> other) -
filter
-
map
-
mapDynamic
-
flatMap
-
selectVar
-
selectVar
-
conditionOn
-
conditionOnShowing
static <T> Val<T> conditionOnShowing(javafx.beans.value.ObservableValue<T> obs, javafx.scene.Node node) -
suspendable
-
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 ObservableValueobs
every timeobs
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 ofobs
), instead of any intermediate interpolated value.- Parameters:
obs
- observable value to animateduration
- 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 ObservableValueobs
every timeobs
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 ofobs
), instead of any intermediate interpolated value.- Parameters:
obs
- observable value to animateduration
- the desired duration of the transitioninterpolator
- 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) Likeanimate(ObservableValue, BiFunction, Interpolator)
, but uses the interpolation defined by the Interpolatable typeT
. -
animate
static <T extends javafx.animation.Interpolatable<T>> Val<T> animate(javafx.beans.value.ObservableValue<T> obs, Duration duration) Likeanimate(ObservableValue, Duration, Interpolator)
, but uses the interpolation defined by the Interpolatable typeT
. -
combine
static <A,B, Val<R> combineR> (javafx.beans.value.ObservableValue<A> src1, javafx.beans.value.ObservableValue<B> src2, BiFunction<? super A, ? super B, ? extends R> f) -
combine
static <A,B, Val<R> combineC, R> (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, Val<R> combineC, D, R> (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, Val<R> combineC, D, E, R> (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, Val<R> combineC, D, E, F, R> (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
-
create
-
constant
Returns a constant Val that holds the given value. The value never changes and no notifications are ever produced. -
showingProperty
Returns a Val whose value istrue
whennode
is showing: it is part of a scene graph (Node.sceneProperty()
is notnull
), its scene is part of a window (Scene.windowProperty()
is notnull
) and the window is showing (Window.showingProperty()
istrue
).
-