public final class ValueHolder extends AbstractValueModel
ValueModel implementation
that holds a generic value.
If the value changes, a PropertyChangeEvent is fired
that can be observed using a PropertyChangeListener.
Differences in the old and new value can be checked either using
== or #equals. The unbound property
identityCheckEnabled determines which mechanism is used
to check for changes in #setValue(Object).
This check can be overridden for individual changes by the boolean
parameter in #setValue(Object, boolean).
Constraints: The value is of type Object.
ValueModel,
PropertyChangeEvent,
PropertyChangeListener,
ExtendedPropertyChangeSupport,
Serialized FormPROPERTY_VALUE| Constructor and Description |
|---|
ValueHolder()
Constructs a
ValueHolder with null
as initial value. |
ValueHolder(boolean initialValue)
Constructs a
ValueHolder with the specified initial
boolean value that is converted to a Boolean object. |
ValueHolder(double initialValue)
Constructs a
ValueHolder with the specified initial
double value that is converted to a Double object. |
ValueHolder(float initialValue)
Constructs a
ValueHolder with the specified initial
float value that is converted to a Float object. |
ValueHolder(int initialValue)
Constructs a
ValueHolder with the specified initial
int value that is converted to an Integer object. |
ValueHolder(long initialValue)
Constructs a
ValueHolder with the specified initial
long value that is converted to a Long object. |
ValueHolder(Object initialValue)
Constructs a
ValueHolder with the given initial value. |
ValueHolder(Object initialValue,
boolean checkIdentity)
Constructs a
ValueHolder with the given initial value. |
| Modifier and Type | Method and Description |
|---|---|
Object |
getValue()
Returns the observed value.
|
boolean |
isIdentityCheckEnabled()
Answers whether this ValueHolder fires value change events if
and only if the old and new value are not the same.
|
void |
setIdentityCheckEnabled(boolean checkIdentity)
Sets the comparison that is used to check differences between
the old and new value when firing value change events.
|
void |
setValue(Object newValue)
Sets a new value.
|
void |
setValue(Object newValue,
boolean checkIdentity)
Sets a new value.
|
addValueChangeListener, booleanValue, doubleValue, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, floatValue, getString, intValue, longValue, paramString, removeValueChangeListener, setValue, setValue, setValue, setValue, setValue, toString, valueStringcreatePropertyChangeSupport, firePropertyChangeaddPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, fireMultiplePropertiesChanged, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListenerpublic ValueHolder()
ValueHolder with null
as initial value.public ValueHolder(Object initialValue)
ValueHolder with the given initial value.
By default the old and new value are compared using #equals
when firing value change events.initialValue - the initial valuepublic ValueHolder(Object initialValue, boolean checkIdentity)
ValueHolder with the given initial value.initialValue - the initial valuecheckIdentity - true to compare the old and new value using
==, false to use #equalspublic ValueHolder(boolean initialValue)
ValueHolder with the specified initial
boolean value that is converted to a Boolean object.initialValue - the initial boolean valuepublic ValueHolder(double initialValue)
ValueHolder with the specified initial
double value that is converted to a Double object.initialValue - the initial double valuepublic ValueHolder(float initialValue)
ValueHolder with the specified initial
float value that is converted to a Float object.initialValue - the initial float valuepublic ValueHolder(int initialValue)
ValueHolder with the specified initial
int value that is converted to an Integer object.initialValue - the initial int valuepublic ValueHolder(long initialValue)
ValueHolder with the specified initial
long value that is converted to a Long object.initialValue - the initial long valuepublic Object getValue()
public void setValue(Object newValue)
== if
isIdentityCheckEnabled answers true.
The values are compared with #equals if the
identity check is disabled.newValue - the new valuepublic boolean isIdentityCheckEnabled()
true if the old and new value are compared
using ==, false if the values
are compared using #equalspublic void setIdentityCheckEnabled(boolean checkIdentity)
#setValue(Object). You can override this default setting
by changing a value via #setValue(Object, boolean).checkIdentity - true to compare the old and new value using
==, false to use #equalspublic void setValue(Object newValue, boolean checkIdentity)
== if
checkIdentity is true. The values are
compared with #equals if the checkIdentiy
parameter is set to false.
Unlike general bean property setters, this method does not fire
an event if the old and new value are null.
newValue - the new valuecheckIdentity - true to compare the old and new value using
==, false to use #equalsCopyright © 2002-2015 JGoodies Software GmbH. All Rights Reserved.