- Type Parameters:
T- the value type
- All Implemented Interfaces:
Observable<T>,Observer<T>,Value<T>
- Direct Known Subclasses:
AbstractComponentValue,PropertyValue
An abstract Value implementation handling everything except the value itself.
The constructor parameter notify specifies whether this AbstractValue instance should call
notifyObserver() each time the value is set (Value.Notify.SET) or only when it changes
(Value.Notify.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
ConstructorsModifierConstructorDescriptionprotectedCreates a nullableAbstractValueinstance, which does not notify listeners.protectedAbstractValue(@Nullable T nullValue) Creates anAbstractValueinstance, which does not notify listeners.protectedAbstractValue(@Nullable T nullValue, Value.Notify notify) Creates anAbstractValueinstance.protectedAbstractValue(Value.Notify notify) Creates a nullableAbstractValueinstance. -
Method Summary
Modifier and TypeMethodDescriptionfinal booleanaddValidator(Value.Validator<? super T> validator) Adds a validator to thisValue.final voidclear()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 booleanIf false then get() is guaranteed to never return null.final voidlink(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 voidCreates a bidirectional link between this and the given original value, so that changes in one are reflected in the other.final voidmap(UnaryOperator<@Nullable T> mapper) Sets a new value mapped from the current value.protected final voidNotifies the underlying observer that the underlying value has changed or at least that it may have changedobserver()final booleanremoveValidator(Value.Validator<? super T> validator) Removes the given validator from this valuefinal voidSets the value.protected abstract voidSets the actual internal value.final voidunlink(Observable<T> observable) Unlinks this value from the given observablefinal voidUnlinks this value from the given original valuefinal voidValidate the given value using all validatorsMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface is.codion.common.observer.Observable
addConsumer, addListener, addWeakConsumer, addWeakListener, getOrThrow, getOrThrow, is, isNot, isNull, optional, removeConsumer, removeListener, removeWeakConsumer, removeWeakListener
-
Constructor Details
-
AbstractValue
protected AbstractValue()Creates a nullable
AbstractValueinstance, which does not notify listeners. -
AbstractValue
Creates a nullableAbstractValueinstance.- Parameters:
notify- specifies when to notify listeners
-
AbstractValue
Creates an
AbstractValueinstance, which does not notify listeners.If
nullValueis non-null, thisAbstractValueinstance 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
AbstractValueinstance.If
nullValueis non-null, thisAbstractValueinstance 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:
getin interfaceObservable<T>- Returns:
- the value
-
set
Description copied from interface:ValueSets the value. Note that change listener notifications depend on theValue.Notifypolicy associated with this value. -
clear
public final void clear()Description copied from interface:ValueClears this value, by setting it to null or the null value in case this is a non-null value. -
map
Description copied from interface:ValueSets 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:
observablein interfaceValue<T>- Returns:
- a read-only
Observableinstance for this value
-
observer
- Specified by:
observerin interfaceObservable<T>- Returns:
- an
Observernotified each time the observed value may have changed
-
isNullable
public final boolean isNullable()Description copied from interface:ObservableIf false then get() is guaranteed to never return null.- Specified by:
isNullablein interfaceObservable<T>- Returns:
- true if this observable can be null
-
link
Description copied from interface:ValueCreates 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:ValueUnlinks this value from the given original value -
link
Description copied from interface:ValueCreates 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:ValueUnlinks this value from the given observable -
addValidator
Description copied from interface:ValueAdds a validator to thisValue. Adding the same validator again has no effect.- Specified by:
addValidatorin interfaceValue<T>- Parameters:
validator- the validator- Returns:
- true if this value did not already contain the specified validator
-
removeValidator
Description copied from interface:ValueRemoves the given validator from this value- Specified by:
removeValidatorin interfaceValue<T>- Parameters:
validator- the validator- Returns:
- true if this value contained the specified validator
-
validate
Description copied from interface:ValueValidate 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
-
notifyObserver
protected final void notifyObserver()Notifies the underlying observer that the underlying value has changed or at least that it may have changed -
createObservable
- Returns:
- a new
Observableinstance representing this value
-