Module com.tobiasdiez.easybind
Package com.tobiasdiez.easybind.optional
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 -
Method Summary
Modifier and TypeMethodDescriptionReturns 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.<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.javafx.beans.binding.BooleanBindingisEmpty()Returns a new observable that holdstrueif this observable does not hold value, orfalseotherwise.javafx.beans.binding.BooleanBindingReturns a new observable that holdstrueif this observable holds value, orfalseotherwise.<U> OptionalBinding<U>Returns anObservableValuethat holds the result of applying the given mapping function on this value.Returns a new observable that holds the value held by this observable, or the value held byotherwhen this observable is empty.Returns a new observable that holds the value held by this observable, orotherwhen this observable is empty.Methods inherited from class com.tobiasdiez.easybind.PreboundBinding
disposeMethods inherited from class javafx.beans.binding.ObjectBinding
addListener, addListener, allowValidation, bind, computeValue, get, getDependencies, invalidate, isObserved, isValid, onInvalidating, removeListener, removeListener, toString, unbindMethods inherited from class javafx.beans.binding.ObjectExpression
asString, asString, asString, getValue, isEqualTo, isEqualTo, isNotEqualTo, isNotEqualTo, isNotNull, isNull, objectExpressionMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface javafx.beans.binding.Binding
dispose, getDependencies, invalidate, isValidMethods inherited from interface javafx.beans.Observable
addListener, removeListenerMethods inherited from interface javafx.beans.value.ObservableObjectValue
getMethods inherited from interface com.tobiasdiez.easybind.optional.ObservableOptionalValue
asOrdinary, getValueOrElse, getValueOrElseThrow, ifValuePresent, isValueEmpty, isValuePresent, listen, listenToValues, mapObservable, selectProperty, subscribe, subscribeToValuesMethods 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
Description copied from interface:ObservableOptionalValueReturns anObservableValuethat holds the result of applying the given mapping function on this value. The result is updated when thisObservableOptionalValuechanges. If this value is an empty optional, no mapping is applied and the resulting value is also an empty optional. If the function returnsnull, then this is converted into an empty optional.This method is similar to the JavaFX 19 method
mapbut with special handling of empty optionals instead ofnullvalues.- Specified by:
mapOptin interfaceObservableOptionalValue<T>- Parameters:
mapper- the mapping to apply to a value, if present- See Also:
-
flatMapOpt
Description copied from interface:ObservableOptionalValueReturns 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 anOptional, and if invoked,flatMapdoes not wrap it within an additionalOptional.This method should not be confused with the JavaFX 19 method
flatMapwhich accepts amapperproducing an observable value, and not anOptional.- Specified by:
flatMapOptin interfaceObservableOptionalValue<T>- Parameters:
mapper- the mapping to apply to a value, if present
-
orElseOpt
Description copied from interface:ObservableOptionalValueReturns a new observable that holds the value held by this observable, orotherwhen this observable is empty.This method is similar to the JavaFX 19 method
orElsebut recognizes an empty optional instead ofnullvalues.- Specified by:
orElseOptin interfaceObservableOptionalValue<T>
-
orElseOpt
Description copied from interface:ObservableOptionalValueReturns a new observable that holds the value held by this observable, or the value held byotherwhen this observable is empty.This method is similar to the JavaFX 19 method
orElsebut recognizes an empty optional instead ofnullvalues and allows an observable as fallback.- Specified by:
orElseOptin interfaceObservableOptionalValue<T>
-
filter
Description copied from interface:ObservableOptionalValueReturns 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:
filterin interfaceObservableOptionalValue<T>- Parameters:
predicate- the predicate to apply to a value, if present
-
isPresent
public javafx.beans.binding.BooleanBinding isPresent()Description copied from interface:ObservableOptionalValueReturns a new observable that holdstrueif this observable holds value, orfalseotherwise.- Specified by:
isPresentin interfaceObservableOptionalValue<T>
-
isEmpty
public javafx.beans.binding.BooleanBinding isEmpty()Description copied from interface:ObservableOptionalValueReturns a new observable that holdstrueif this observable does not hold value, orfalseotherwise.- Specified by:
isEmptyin interfaceObservableOptionalValue<T>
-