java.lang.Object
is.codion.common.value.AbstractValue<T>
- Type Parameters:
T- the value type
- All Implemented Interfaces:
EventObserver<T>,Value<T>,ValueObserver<T>,Consumer<T>,Supplier<T>
An abstract
The constructor parameter
Value implementation handling everything except the value itself.The constructor parameter
notify specifies whether this Value instance should automatically call
notifyListeners() when the value is set or changed via set(Object).
Some implementations may want to handle this manually.-
Nested Class Summary
Nested classes/interfaces inherited from interface is.codion.common.value.Value
Value.Builder<T,B extends Value.Builder<T, B>>, Value.Notify, Value.Validator<T> -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedprotectedAbstractValue(T nullValue) Creates anAbstractValueinstance, which does not notify listeners.protectedAbstractValue(T nullValue, Value.Notify notify) Creates anAbstractValueinstance. -
Method Summary
Modifier and TypeMethodDescriptionfinal voidSets the value.final booleanaddConsumer(Consumer<? super T> consumer) Addsconsumerto thisEventObserver.final booleanaddListener(Runnable listener) Addslistenerto thisEventObserver.final booleanaddValidator(Value.Validator<? super T> validator) Adds a validator to thisValue.final booleanaddWeakConsumer(Consumer<? super T> consumer) Uses aWeakReference, addingconsumerdoes not prevent it from being garbage collected.final booleanaddWeakListener(Runnable listener) Uses aWeakReference, addinglistenerdoes not prevent it from being garbage collected.final voidclear()Clears this value, by setting it to null or the null value in case this is a non-null value.protected voidClears this value by setting it to null.protected ValueObserver<T>final booleanIf false then get() is guaranteed to never return null.final voidCreates a bidirectional link between this and the given original value, so that changes in one are reflected in the other.final voidlink(ValueObserver<T> originalValue) Creates a unidirectional link between this value and the given original value observer, so that changes in the original value are reflected in this one.final booleanSets a new value mapped from the current value.protected final voidNotifies listeners that the underlying value has changed or at least that it may have changedobserver()Returns aValueObservernotified each time this value changes.final booleanremoveConsumer(Consumer<? super T> consumer) Removesconsumerfrom thisEventObserverfinal booleanremoveListener(Runnable listener) Removeslistenerfrom thisEventObserverfinal booleanremoveValidator(Value.Validator<? super T> validator) Removes the given validator from this valuefinal booleanremoveWeakConsumer(Consumer<? super T> consumer) Removesconsumerfrom thisEventObserver.final booleanremoveWeakListener(Runnable listener) Removeslistenerfrom thisEventObserverfinal booleanSets the value.protected abstract voidSets the actual internal value.final voidUnlinks this value from the given original valuefinal voidunlink(ValueObserver<T> originalValue) Unlinks this value from the given original value observerfinal 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.value.ValueObserver
isEqualTo, isNotEqualTo, isNotNull, isNull, optional
-
Constructor Details
-
AbstractValue
protected AbstractValue() -
AbstractValue
Creates anAbstractValueinstance, which does not notify listeners.- Parameters:
nullValue- the value to use instead of null
-
AbstractValue
Creates anAbstractValueinstance.- Parameters:
nullValue- the value to use instead of nullnotify- specifies when to notify listeners
-
-
Method Details
-
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); -
observer
Description copied from interface:ValueReturns aValueObservernotified each time this value changes.- Specified by:
observerin interfaceValue<T>- Returns:
- a
ValueObserverfor this value
-
isNullable
public final boolean isNullable()Description copied from interface:ValueObserverIf false then get() is guaranteed to never return null.- Specified by:
isNullablein interfaceValueObserver<T>- Returns:
- true if this value can be null
-
accept
Description copied from interface:ValueSets the value. Note that change listener notifications depend on theValue.Notifypolicy associated with this value. -
addListener
Description copied from interface:EventObserverAddslistenerto thisEventObserver. Adding the same listener a second time has no effect.- Specified by:
addListenerin interfaceEventObserver<T>- Parameters:
listener- the listener to add- Returns:
- true if this observer did not already contain the specified listener
-
removeListener
Description copied from interface:EventObserverRemoveslistenerfrom thisEventObserver- Specified by:
removeListenerin interfaceEventObserver<T>- Parameters:
listener- the listener to remove- Returns:
- true if this observer contained the specified listener
-
addConsumer
Description copied from interface:EventObserverAddsconsumerto thisEventObserver. Adding the same consumer a second time has no effect.- Specified by:
addConsumerin interfaceEventObserver<T>- Parameters:
consumer- the consumer to add- Returns:
- true if this observer did not already contain the specified consumer
-
removeConsumer
Description copied from interface:EventObserverRemovesconsumerfrom thisEventObserver- Specified by:
removeConsumerin interfaceEventObserver<T>- Parameters:
consumer- the consumer to remove- Returns:
- true if this observer contained the specified consumer
-
addWeakListener
Description copied from interface:EventObserverUses aWeakReference, addinglistenerdoes not prevent it from being garbage collected. Adding the same listener a second time has no effect.- Specified by:
addWeakListenerin interfaceEventObserver<T>- Parameters:
listener- the listener- Returns:
- true if this observer did not already contain the specified listener
-
removeWeakListener
Description copied from interface:EventObserverRemoveslistenerfrom thisEventObserver- Specified by:
removeWeakListenerin interfaceEventObserver<T>- Parameters:
listener- the listener to remove- Returns:
- true if this observer contained the specified listener
-
addWeakConsumer
Description copied from interface:EventObserverUses aWeakReference, addingconsumerdoes not prevent it from being garbage collected. Adding the same consumer a second time has no effect.- Specified by:
addWeakConsumerin interfaceEventObserver<T>- Parameters:
consumer- the consumer- Returns:
- true if this observer did not already contain the specified consumer
-
removeWeakConsumer
Description copied from interface:EventObserverRemovesconsumerfrom thisEventObserver.- Specified by:
removeWeakConsumerin interfaceEventObserver<T>- Parameters:
consumer- the consumer to remove- Returns:
- true if this observer contained the specified consumer
-
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 original value observer, so that changes in the original value are reflected in this one. Note that after a call to this method the value of this value is the same as the original value. -
unlink
Description copied from interface:ValueUnlinks this value from the given original value observer -
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 -
setValue
Sets the actual internal value.- Parameters:
value- the value
-
clearValue
protected void clearValue()Clears this value by setting it to null. -
notifyListeners
protected final void notifyListeners()Notifies listeners that the underlying value has changed or at least that it may have changed -
createObserver
- Returns:
- a new
ValueObserverinstance representing this value
-