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 voidaddInvalidationObserver(Consumer<? super T> observer) default voidaddListener(javafx.beans.InvalidationListener listener) default voidaddListener(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 ObservableValueobsevery timeobschanges.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 ObservableValueobsevery timeobschanges.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 thatnodeis 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 TReturns the value currently held by this Val.default TgetOrSupply(Supplier<? extends T> defaultSupplier) LikegetOrElse(Object), except the default value is computed bydefaultSupplieronly when necessary.default TReturns the value currently held by this Val.default voidInvokes 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 booleanisEmpty()Inverse ofisPresent().default booleanChecks 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 SubscriptionobserveChanges(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> SubscriptionobserveChanges(javafx.beans.value.ObservableValue<? extends T> obs, javafx.beans.value.ChangeListener<? super T> listener) default SubscriptionobserveInvalidations(Consumer<? super T> oldValueObserver) static SubscriptionobserveInvalidations(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 Subscriptionpin()default voidremoveInvalidationObserver(Consumer<? super T> observer) default voidremoveListener(javafx.beans.InvalidationListener listener) default voidremoveListener(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 istruewhennodeis 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 Observable
addObserver, observe, removeObserverMethods inherited from interface javafx.beans.value.ObservableValue
getValue
-
Method Details
-
addInvalidationObserver
-
removeInvalidationObserver
-
observeInvalidations
-
pin
-
addListener
default void addListener(javafx.beans.InvalidationListener listener) - Specified by:
addListenerin interfacejavafx.beans.Observable
-
removeListener
default void removeListener(javafx.beans.InvalidationListener listener) - Specified by:
removeListenerin interfacejavafx.beans.Observable
-
addListener
-
removeListener
-
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
-
isEmpty
default boolean isEmpty()Inverse ofisPresent(). -
ifPresent
-
getOrThrow
Returns the value currently held by this Val.- Throws:
NoSuchElementException- if there is no value present.
-
getOrElse
-
getOrSupply
LikegetOrElse(Object), except the default value is computed bydefaultSupplieronly when necessary.- Parameters:
defaultSupplier- computation to produce default value, if this Val is empty.
-
getOpt
-
orElseConst
-
orElse
-
filter
-
map
-
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 returnnullregardless of any prior call tosetValue()orbind(). -
selectVar
-
conditionOn
Returns a new Val that only observes this Val whenconditionistrue. More precisely, the returned Val observesconditionwhenever it itself has at least one observer and observesthisVal whenever it itself has at least one observer and the value ofconditionistrue. Whenconditionistrue, the returned Val has the same value as this Val. Whenconditionisfalse, the returned Val has the value that was held by this Val at the time whenconditionchanged tofalse. -
conditionOnShowing
Equivalent toconditionOn(ObservableValue)where the condition is thatnodeis 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
-
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 of
one can writeVal.wrap(obs).orElse(other)
However, an explicit wrapper is necessary if access toVal.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 ObservableValueobsevery timeobschanges.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 ObservableValueobsevery timeobschanges.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
-
showingProperty
Returns a Val whose value istruewhennodeis 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).
-