T
- the value typepublic abstract class AbstractValue<T> extends Object implements Value<T>
Value
implementation handling everything except the value itself.notifyOnSet
specifies whether this Value
instance should automatically call
notifyValueChange()
when the value is changed via set(Object)
.
Some implementations may want to do this manually.Value.Validator<T>
Modifier | Constructor and Description |
---|---|
protected |
AbstractValue() |
protected |
AbstractValue(T nullValue)
Creates an
AbstractValue instance, which does not notify on set. |
protected |
AbstractValue(T nullValue,
boolean notifyOnSet)
Creates an
AbstractValue instance. |
Modifier and Type | Method and Description |
---|---|
void |
addDataListener(EventDataListener<T> listener)
Adds
listener to this EventObserver , adding the same listener
a second time has no effect. |
void |
addListener(EventListener listener)
Adds
listener to this EventObserver , adding the same listener
a second time has no effect. |
void |
addValidator(Value.Validator<T> validator)
Adds a validator to this
Value . |
protected EventObserver<T> |
changeObserver() |
boolean |
isNullable()
If false then get() is guaranteed to never return null.
|
void |
link(Value<T> originalValue)
Creates a bidirectional link between this and the given original value,
so that changes in one are reflected in the other.
|
void |
link(ValueObserver<T> originalValueObserver)
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.
|
Set<Value<T>> |
linkedValues() |
protected void |
notifyValueChange()
Triggers the change event for this value, using the current value, indicating that
the underlying value has changed or at least that it may have changed
|
ValueObserver<T> |
observer()
Returns a
ValueObserver notified each time this value changes. |
void |
onEvent(T data)
Called when the event occurs.
|
void |
removeDataListener(EventDataListener<T> listener)
Removes
listener from this EventObserver |
void |
removeListener(EventListener listener)
Removes
listener from this EventObserver |
void |
removeValidator(Value.Validator<T> validator)
Removes the given validator from this value
|
void |
set(T value)
Sets the value
|
protected abstract void |
setValue(T value)
Sets the actual internal value.
|
void |
unlink(Value<T> originalValue)
Unlinks this value from the given original value
|
void |
unlink(ValueObserver<T> originalValueObserver)
Unlinks this value from the given original value observer
|
Collection<Value.Validator<T>> |
validators() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
propertyValue, value, value, value, value, value
equalTo, isNotNull, isNull, toOptional
protected AbstractValue()
protected AbstractValue(T nullValue)
AbstractValue
instance, which does not notify on set.nullValue
- the value to use instead of nullprotected AbstractValue(T nullValue, boolean notifyOnSet)
AbstractValue
instance.nullValue
- the value to use instead of nullnotifyOnSet
- specifies whether to automatically call notifyValueChange()
when the value is changed via set(Object)
public final ValueObserver<T> observer()
Value
ValueObserver
notified each time this value changes.observer
in interface Value<T>
ValueObserver
for this valuepublic final boolean isNullable()
ValueObserver
isNullable
in interface ValueObserver<T>
public final void onEvent(T data)
EventDataListener
onEvent
in interface EventDataListener<T>
data
- information relating to the event.public final void addListener(EventListener listener)
EventObserver
listener
to this EventObserver
, adding the same listener
a second time has no effect.addListener
in interface EventObserver<T>
listener
- the listener to addpublic final void removeListener(EventListener listener)
EventObserver
listener
from this EventObserver
removeListener
in interface EventObserver<T>
listener
- the listener to removepublic final void addDataListener(EventDataListener<T> listener)
EventObserver
listener
to this EventObserver
, adding the same listener
a second time has no effect.addDataListener
in interface EventObserver<T>
listener
- the listener to addpublic final void removeDataListener(EventDataListener<T> listener)
EventObserver
listener
from this EventObserver
removeDataListener
in interface EventObserver<T>
listener
- the listener to removepublic final void link(Value<T> originalValue)
Value
originalValue
.public final void unlink(Value<T> originalValue)
Value
public final void link(ValueObserver<T> originalValueObserver)
Value
public final void unlink(ValueObserver<T> originalValueObserver)
Value
public final Set<Value<T>> linkedValues()
linkedValues
in interface Value<T>
public final void addValidator(Value.Validator<T> validator)
Value
Value
.
Adding the same validator again has no effect.addValidator
in interface Value<T>
validator
- the validatorpublic final void removeValidator(Value.Validator<T> validator)
Value
removeValidator
in interface Value<T>
validator
- the validatorpublic final Collection<Value.Validator<T>> validators()
validators
in interface Value<T>
protected abstract void setValue(T value)
value
- the valueprotected EventObserver<T> changeObserver()
protected final void notifyValueChange()