K
- the key typeV
- the value typepublic class DefaultValueMap<K,V> extends java.lang.Object implements ValueMap<K,V>
Modifier and Type | Class and Description |
---|---|
static class |
DefaultValueMap.DefaultValidator<K,V extends ValueMap<K,?>>
A default value map validator implementation, which performs basic null validation.
|
Modifier | Constructor and Description |
---|---|
|
DefaultValueMap()
Instantiates a new empty instance
|
protected |
DefaultValueMap(java.util.Map<K,V> values,
java.util.Map<K,V> originalValues)
Instantiates a new instance using the given maps for the values and original values respectively.
|
Modifier and Type | Method and Description |
---|---|
void |
addValueListener(EventDataListener<ValueChange<K,V>> valueListener)
Adds a listener notified each time a value changes
Adding the same listener multiple times has no effect.
|
void |
clear()
Silently removes all values from this map, as in, removes the values
without firing value change events
|
boolean |
containsKey(K key)
Returns true if this ValueMap contains a value for the given key, that value can be null.
|
protected V |
copy(V value)
Returns a deep copy of the given value, immutable values are simply returned.
|
boolean |
equals(java.lang.Object obj)
Two DefaultValueMap objects are equal if they contain the
same number of values and all their values are equal.
|
V |
get(K key)
Retrieves the value mapped to the given key
|
java.lang.String |
getAsString(K key)
Retrieves a string representation of the value mapped to the given key, an empty string is returned
in case of null values or if key is not found.
|
ValueMap<K,V> |
getCopy() |
StateObserver |
getModifiedObserver() |
V |
getOriginal(K key)
Returns the original value associated with the given key or the current value if it has not been modified.
|
ValueMap<K,V> |
getOriginalCopy() |
EventObserver<ValueChange<K,V>> |
getValueObserver()
Returns an EventObserver notified each time a value changes, with a
ValueChange argument. |
protected void |
handleClear()
Called after the value map has been cleared.
|
protected void |
handlePut(K key,
V value,
V previousValue,
boolean initialization)
Called after a value has been put.
|
protected void |
handleRemove(K key,
V value)
Called after a value has been removed from this map.
|
protected void |
handleValueChangedEventInitialized()
Called after the valueChangeEvent has been initialized, via the first call to
getValueChangedEvent() |
int |
hashCode() |
boolean |
isModified() |
boolean |
isModified(K key)
Returns true if the value associated with the given key has been modified..
|
boolean |
isNotNull(K key)
Returns true if a this ValueMap contains a non-null value mapped to the given key
|
boolean |
isNull(K key)
Returns true if a null value is mapped to the given key or the key is not found.
|
java.util.Set<K> |
keySet() |
ValueMap<K,V> |
newInstance() |
protected void |
notifyValueChange(K key,
V currentValue,
V previousValue,
boolean initialization) |
java.util.Set<K> |
originalKeySet() |
V |
put(K key,
V value)
Maps the given value to the given key, returning the old value if any.
|
V |
remove(K key)
Removes the given key and value from this value map along with the original value if any.
|
protected void |
removeOriginalValue(K key) |
void |
removeValueListener(EventDataListener valueListener)
Removes the given value listener if it has been registered with this value map.
|
void |
revert(K key)
Reverts the value associated with the given key to its original value.
|
void |
revertAll()
Reverts all value modifications that have been made.
|
void |
save(K key)
Saves the value associated with the given key, that is, removes the original value.
|
void |
saveAll()
Saves all the value modifications that have been made.
|
void |
setAs(ValueMap<K,V> sourceMap)
After a call to this method this ValueMap contains the same values and original values as the source map.
|
protected void |
setOriginalValue(K key,
V previousValue) |
int |
size() |
java.util.Collection<V> |
values()
Retrieves the values associated with this value provider.
|
public DefaultValueMap()
protected DefaultValueMap(java.util.Map<K,V> values, java.util.Map<K,V> originalValues)
values
- the valuesoriginalValues
- the originalValuespublic boolean isNull(K key)
public boolean isNotNull(K key)
public V put(K key, V value)
public V get(K key)
get
in interface ValueProvider<K,V>
key
- the keypublic java.lang.String getAsString(K key)
getAsString
in interface ValueMap<K,V>
key
- the keypublic boolean equals(java.lang.Object obj)
equals
in class java.lang.Object
public int hashCode()
hashCode
in class java.lang.Object
public final boolean containsKey(K key)
containsKey
in interface ValueMap<K,V>
key
- the keypublic final V remove(K key)
public final void clear()
public final int size()
public final java.util.Set<K> keySet()
public final java.util.Set<K> originalKeySet()
originalKeySet
in interface ValueMap<K,V>
public final java.util.Collection<V> values()
values
in interface ValueCollectionProvider<V>
public final V getOriginal(K key)
getOriginal
in interface ValueMap<K,V>
key
- the key for which to retrieve the original valuepublic boolean isModified()
isModified
in interface ValueMap<K,V>
public ValueMap<K,V> newInstance()
newInstance
in interface ValueMap<K,V>
public final void setAs(ValueMap<K,V> sourceMap)
public final boolean isModified(K key)
isModified
in interface ValueMap<K,V>
key
- the keypublic final void revert(K key)
public final void revertAll()
public final void save(K key)
public final void saveAll()
public final ValueMap<K,V> getOriginalCopy()
getOriginalCopy
in interface ValueMap<K,V>
public final void addValueListener(EventDataListener<ValueChange<K,V>> valueListener)
addValueListener
in interface ValueMap<K,V>
valueListener
- the listenerValueChange
public final void removeValueListener(EventDataListener valueListener)
removeValueListener
in interface ValueMap<K,V>
valueListener
- the listener to removepublic final StateObserver getModifiedObserver()
getModifiedObserver
in interface ValueMap<K,V>
public final EventObserver<ValueChange<K,V>> getValueObserver()
ValueChange
argument.getValueObserver
in interface ValueMap<K,V>
ValueChange
protected final void notifyValueChange(K key, V currentValue, V previousValue, boolean initialization)
protected final void removeOriginalValue(K key)
protected V copy(V value)
value
- the value to copyprotected void handlePut(K key, V value, V previousValue, boolean initialization)
key
- the keyvalue
- the valuepreviousValue
- the previous valueinitialization
- true if the value was being initializedprotected void handleRemove(K key, V value)
key
- the keyvalue
- the value that was removedprotected void handleClear()
protected void handleValueChangedEventInitialized()
getValueChangedEvent()