- Type Parameters:
T
- the value type
- All Implemented Interfaces:
Observable<T>
,Observer<T>
,Value<T>
- Direct Known Subclasses:
AbstractComponentValue
An abstract Value
implementation handling everything except the value itself.
The constructor parameter notify
specifies whether this AbstractValue
instance should call
notifyListeners()
each time the value is set (Value.Notify.WHEN_SET
) or only when it changes
(Value.Notify.WHEN_CHANGED
), which is determined using Object.equals(Object)
.
Implementations that want to handle notifications manually should use the
AbstractValue()
or AbstractValue(Object)
constructors.
-
Nested Class Summary
Nested classes/interfaces inherited from interface is.codion.common.value.Value
Value.Builder<T,
B extends Value.Builder<T, B>>, Value.BuilderFactory, Value.Notify, Value.Validator<T> -
Constructor Summary
ModifierConstructorDescriptionprotected
Creates a nullableAbstractValue
instance, which does not notify listeners.protected
AbstractValue
(@Nullable T nullValue) Creates anAbstractValue
instance, which does not notify listeners.protected
AbstractValue
(@Nullable T nullValue, Value.Notify notify) Creates anAbstractValue
instance.protected
AbstractValue
(Value.Notify notify) Creates a nullableAbstractValue
instance. -
Method Summary
Modifier and TypeMethodDescriptionfinal boolean
addValidator
(Value.Validator<? super T> validator) Adds a validator to thisValue
.final void
clear()
Clears this value, by setting it to null or the null value in case this is a non-null value.protected Observable<T>
get()
getValue()
Returns the actual internal value.final boolean
If false then get() is guaranteed to never return null.final void
link
(Observable<T> observable) Creates a unidirectional link between this value and the given observable, so that changes in the observable are reflected in this one.final void
Creates a bidirectional link between this and the given original value, so that changes in one are reflected in the other.final boolean
Sets a new value mapped from the current value.protected final void
Notifies listeners that the underlying value has changed or at least that it may have changedobserver()
final boolean
removeValidator
(Value.Validator<? super T> validator) Removes the given validator from this valuefinal boolean
Sets the value.protected abstract void
Sets the actual internal value.final void
unlink
(Observable<T> observable) Unlinks this value from the given observablefinal void
Unlinks this value from the given original valuefinal void
Validate the given value using all validatorsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface is.codion.common.observable.Observable
addConsumer, addListener, addWeakConsumer, addWeakListener, getOrThrow, getOrThrow, isEqualTo, isNotEqualTo, isNull, optional, removeConsumer, removeListener, removeWeakConsumer, removeWeakListener
-
Constructor Details
-
AbstractValue
protected AbstractValue()Creates a nullable
AbstractValue
instance, which does not notify listeners. -
AbstractValue
Creates a nullableAbstractValue
instance.- Parameters:
notify
- specifies when to notify listeners
-
AbstractValue
Creates an
AbstractValue
instance, which does not notify listeners.If
nullValue
is non-null, thisAbstractValue
instance will be non-nullable, meaningisNullable()
returns false,get()
is guaranteed to never return null and whenset(Object)
receives null it is automatically translated tonullValue
.- Parameters:
nullValue
- the value to use instead of null
-
AbstractValue
Creates an
AbstractValue
instance.If
nullValue
is non-null, thisAbstractValue
instance will be non-nullable, meaningisNullable()
returns false,get()
is guaranteed to never return null and whenset(Object)
receives null it is automatically translated tonullValue
.- Parameters:
nullValue
- the value to use instead of nullnotify
- specifies when to notify listeners
-
-
Method Details
-
get
- Specified by:
get
in interfaceObservable<T>
- Returns:
- the value
-
set
Description copied from interface:Value
Sets the value. Note that change listener notifications depend on theValue.Notify
policy associated with this value. -
clear
public final void clear()Description copied from interface:Value
Clears this value, by setting it to null or the null value in case this is a non-null value. -
map
Description copied from interface:Value
Sets a new value mapped from the current value.Value<Integer> value = Value.value(0); // increment the value by one value.map(currentValue -> currentValue + 1);
-
observable
- Specified by:
observable
in interfaceValue<T>
- Returns:
- a read-only
Observable
instance for this value
-
observer
- Specified by:
observer
in interfaceObservable<T>
- Returns:
- an
Observer
notified each time the observed value may have changed
-
isNullable
public final boolean isNullable()Description copied from interface:Observable
If false then get() is guaranteed to never return null.- Specified by:
isNullable
in interfaceObservable<T>
- Returns:
- true if this observable can be null
-
link
Description copied from interface:Value
Creates a bidirectional link between this and the given original value, so that changes in one are reflected in the other. Note that after a call to this method this value is the same asoriginalValue
. -
unlink
Description copied from interface:Value
Unlinks this value from the given original value -
link
Description copied from interface:Value
Creates a unidirectional link between this value and the given observable, so that changes in the observable are reflected in this one. Note that after a call to this method the value of this value is the same as the observable. -
unlink
Description copied from interface:Value
Unlinks this value from the given observable -
addValidator
Description copied from interface:Value
Adds a validator to thisValue
. Adding the same validator again has no effect.- Specified by:
addValidator
in interfaceValue<T>
- Parameters:
validator
- the validator- Returns:
- true if this value did not already contain the specified validator
-
removeValidator
Description copied from interface:Value
Removes the given validator from this value- Specified by:
removeValidator
in interfaceValue<T>
- Parameters:
validator
- the validator- Returns:
- true if this value contained the specified validator
-
validate
Description copied from interface:Value
Validate the given value using all validators -
getValue
Returns the actual internal value.- Returns:
- the value
-
setValue
Sets the actual internal value.- Parameters:
value
- the value
-
notifyListeners
protected final void notifyListeners()Notifies listeners that the underlying value has changed or at least that it may have changed -
createObservable
- Returns:
- a new
Observable
instance representing this value
-