com.jgoodies.binding.value

Class ValueHolder

Implemented Interfaces:
Observable, Serializable, ValueModel

public final class ValueHolder
extends AbstractValueModel

A simple 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.

Version:
$Revision: 1.5 $
Author:
Karsten Lentzsch
See Also:
ValueModel, java.beans.PropertyChangeEvent, java.beans.PropertyChangeListener, ExtendedPropertyChangeSupport

Field Summary

Fields inherited from class com.jgoodies.binding.value.AbstractValueModel

PROPERTYNAME_VALUE

Constructor Summary

ValueHolder()
Constructs a ValueHolder with null as initial value.
ValueHolder(Object initialValue)
Constructs a ValueHolder with the given initial value.
ValueHolder(Object initialValue, boolean checkIdentity)
Constructs a ValueHolder with the given 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.

Method Summary

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.

Methods inherited from class com.jgoodies.binding.value.AbstractValueModel

String toString, addValueChangeListener, booleanValue, doubleValue, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, fireValueChange, floatValue, getString, intValue, longValue, removeValueChangeListener, setValue, setValue, setValue, setValue, setValue

Methods inherited from class com.jgoodies.binding.beans.Model

addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, addVetoableChangeListener, equals, fireIndexedPropertyChange, fireIndexedPropertyChange, fireIndexedPropertyChange, fireMultiplePropertiesChanged, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, fireVetoableChange, getPropertyChangeListeners, getPropertyChangeListeners, getVetoableChangeListeners, getVetoableChangeListeners, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, removeVetoableChangeListener

Constructor Details

ValueHolder

public ValueHolder()
Constructs a ValueHolder with null as initial value.

ValueHolder

public ValueHolder(Object initialValue)
Constructs a ValueHolder with the given initial value. By default the old and new value are compared using #equals when firing value change events.
Parameters:
initialValue - the initial value

ValueHolder

public ValueHolder(Object initialValue,
                   boolean checkIdentity)
Constructs a ValueHolder with the given initial value.
Parameters:
initialValue - the initial value
checkIdentity - true to compare the old and new value using ==, false to use #equals

ValueHolder

public ValueHolder(boolean initialValue)
Constructs a ValueHolder with the specified initial boolean value that is converted to a Boolean object.
Parameters:
initialValue - the initial boolean value

ValueHolder

public ValueHolder(double initialValue)
Constructs a ValueHolder with the specified initial double value that is converted to a Double object.
Parameters:
initialValue - the initial double value

ValueHolder

public ValueHolder(float initialValue)
Constructs a ValueHolder with the specified initial float value that is converted to a Float object.
Parameters:
initialValue - the initial float value

ValueHolder

public ValueHolder(int initialValue)
Constructs a ValueHolder with the specified initial int value that is converted to an Integer object.
Parameters:
initialValue - the initial int value

ValueHolder

public ValueHolder(long initialValue)
Constructs a ValueHolder with the specified initial long value that is converted to a Long object.
Parameters:
initialValue - the initial long value

Method Details

getValue

public Object getValue()
Returns the observed value.
Specified by:
getValue in interface ValueModel
Returns:
the observed value

isIdentityCheckEnabled

public boolean isIdentityCheckEnabled()
Answers whether this ValueHolder fires value change events if and only if the old and new value are not the same.
Returns:
true if the old and new value are compared using ==, false if the values are compared using #equals

setIdentityCheckEnabled

public void setIdentityCheckEnabled(boolean checkIdentity)
Sets the comparison that is used to check differences between the old and new value when firing value change events. This is the default setting that is used when changing the value via #setValue(Object). You can override this default setting by changing a value via #setValue(Object, boolean).
Parameters:
checkIdentity - true to compare the old and new value using ==, false to use #equals

setValue

public void setValue(Object newValue)
Sets a new value. Fires a value change event if the old and new value differ. The difference is tested with == if isIdentityCheckEnabled answers true. The values are compared with #equals if the identity check is disabled.
Specified by:
setValue in interface ValueModel
Parameters:
newValue - the new value

setValue

public void setValue(Object newValue,
                     boolean checkIdentity)
Sets a new value. Fires a value change event if the old and new value differ. The difference is tested with == 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.

Parameters:
newValue - the new value
checkIdentity - true to compare the old and new value using ==, false to use #equals

Copyright © 2002-2007 JGoodies Karsten Lentzsch. All Rights Reserved.