org.jminor.common.model.valuemap
Class ValueChangeMapImpl<K,V>

java.lang.Object
  extended by org.jminor.common.model.valuemap.ValueMapImpl<K,V>
      extended by org.jminor.common.model.valuemap.ValueChangeMapImpl<K,V>
Type Parameters:
K - the type of the map keys
V - the type of the map values
All Implemented Interfaces:
ValueAsStringProvider<K>, ValueChangeMap<K,V>, ValueCollectionProvider<V>, ValueMap<K,V>, ValueProvider<K,V>

public class ValueChangeMapImpl<K,V>
extends ValueMapImpl<K,V>
implements ValueChangeMap<K,V>

A default ValueChangeMap implementation.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jminor.common.model.valuemap.ValueMap
ValueMap.ToString<K>
 
Constructor Summary
ValueChangeMapImpl()
           
 
Method Summary
 void addValueListener(ActionListener valueListener)
          Adds a ActionListener, this listener will be notified each time a value changes, by calling actionPerformed() with a ValueChangeEvent argument.
 ValueChangeMap<K,V> getCopy()
          
 ValueChangeMap<K,V> getInstance()
          
 StateObserver getModifiedState()
          
 ValueChangeMap<K,V> getOriginalCopy()
          
 V getOriginalValue(K key)
          Returns the original value associated with the given key or the current value if it has not been changed.
 Collection<K> getOriginalValueKeys()
          
 EventObserver getValueChangeObserver()
          Returns an Event fired each time a value changes, with a ValueChangeEvent argument.
protected  void handleClear()
          Called after the value map has been cleared.
protected  void handleSetAs(ValueChangeMap<K,V> sourceMap)
          Called after the value map has been set.
protected  void handleValueChangedEventInitialized()
           
protected  void handleValueInitialized(K key, V value)
           
protected  void handleValueRemoved(K key, V value)
          Called after a value has been removed from this map.
protected  void handleValueSet(K key, V value, V previousValue, boolean initialization)
          Called after a value has been set.
 void initializeValue(K key, V value)
          Initializes the value associated with the given key.
 boolean isModified()
          
 boolean isModified(K key)
          Returns true if the value associated with the given key has been modified..
protected  void notifyValueChange(K key, V value, V oldValue, boolean initialization)
           
protected  void removeOriginalValue(K key)
           
 void removeValueListener(ActionListener valueListener)
          Removes the given value listener if it has been registered with this value map.
 void revertAll()
          Reverts all value changes that have been made.
 void revertValue(K key)
          Reverts the value associated with the given key to its original value.
 void saveAll()
          Saves all the value changes that have been made.
 void saveValue(K key)
          Saves the value associated with the given key, that is, removes the original value.
 void setAs(ValueChangeMap<K,V> sourceMap)
          After a call to this method this ValueChangeMap contains the same values and original values as the given map.
protected  void setOriginalValue(K key, V oldValue)
           
 
Methods inherited from class org.jminor.common.model.valuemap.ValueMapImpl
clear, containsValue, copyValue, equals, getValue, getValueAsString, getValueKeys, getValues, hashCode, isValueNull, removeValue, setValue, size
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface org.jminor.common.model.valuemap.ValueMap
clear, containsValue, copyValue, getValueKeys, getValues, isValueNull, removeValue, setValue, size
 
Methods inherited from interface org.jminor.common.model.valuemap.ValueProvider
getValue
 
Methods inherited from interface org.jminor.common.model.valuemap.ValueAsStringProvider
getValueAsString
 

Constructor Detail

ValueChangeMapImpl

public ValueChangeMapImpl()
Method Detail

initializeValue

public void initializeValue(K key,
                            V value)
Initializes the value associated with the given key. This method assumes no value has been associated with the key prior to this call, use with care.

Specified by:
initializeValue in interface ValueChangeMap<K,V>
Parameters:
key - the key with which to associate the given value
value - the value to associate with the given key

getOriginalValue

public final V getOriginalValue(K key)
Returns the original value associated with the given key or the current value if it has not been changed.

Specified by:
getOriginalValue in interface ValueChangeMap<K,V>
Parameters:
key - the key for which to retrieve the original value
Returns:
the original value

isModified

public boolean isModified()

Specified by:
isModified in interface ValueChangeMap<K,V>
Returns:
true if a value has been modified.

getInstance

public ValueChangeMap<K,V> getInstance()

Specified by:
getInstance in interface ValueChangeMap<K,V>
Returns:
a new ValueChangeMap instance compatible with this instance

getCopy

public final ValueChangeMap<K,V> getCopy()

Specified by:
getCopy in interface ValueChangeMap<K,V>
Returns:
a deep copy of this value map

setAs

public final void setAs(ValueChangeMap<K,V> sourceMap)
After a call to this method this ValueChangeMap contains the same values and original values as the given map. A null argument to this method clears the destination map of all values and original values.

Specified by:
setAs in interface ValueChangeMap<K,V>
Parameters:
sourceMap - the map to copy or null for clearing the destination map

isModified

public final boolean isModified(K key)
Returns true if the value associated with the given key has been modified..

Specified by:
isModified in interface ValueChangeMap<K,V>
Parameters:
key - the key
Returns:
true if the value has changed

revertValue

public final void revertValue(K key)
Reverts the value associated with the given key to its original value. If the value has not been changed then calling this method has no effect.

Specified by:
revertValue in interface ValueChangeMap<K,V>
Parameters:
key - the key for which to revert the value

revertAll

public final void revertAll()
Reverts all value changes that have been made. This value map will be unmodified after a call to this method. If no changes have been made then calling this method has no effect.

Specified by:
revertAll in interface ValueChangeMap<K,V>

saveValue

public final void saveValue(K key)
Saves the value associated with the given key, that is, removes the original value. If no original value exists calling this method has no effect.

Specified by:
saveValue in interface ValueChangeMap<K,V>
Parameters:
key - the key for which to save the value

saveAll

public final void saveAll()
Saves all the value changes that have been made. This value map will be unmodified after a call to this method.

Specified by:
saveAll in interface ValueChangeMap<K,V>

getOriginalCopy

public final ValueChangeMap<K,V> getOriginalCopy()

Specified by:
getOriginalCopy in interface ValueChangeMap<K,V>
Returns:
a deep copy of this value map in it's original state

getOriginalValueKeys

public final Collection<K> getOriginalValueKeys()

Specified by:
getOriginalValueKeys in interface ValueChangeMap<K,V>
Returns:
an unmodifiable view of the keys mapping the original values in this ValueChangeMap

addValueListener

public final void addValueListener(ActionListener valueListener)
Adds a ActionListener, this listener will be notified each time a value changes, by calling actionPerformed() with a ValueChangeEvent argument. Adding the same listener multiple times has no effect.

Specified by:
addValueListener in interface ValueChangeMap<K,V>
Parameters:
valueListener - the ActionListener
See Also:
ValueChangeEvent

removeValueListener

public final void removeValueListener(ActionListener valueListener)
Removes the given value listener if it has been registered with this value map.

Specified by:
removeValueListener in interface ValueChangeMap<K,V>
Parameters:
valueListener - the ActionListener to remove

getModifiedState

public final StateObserver getModifiedState()

Specified by:
getModifiedState in interface ValueChangeMap<K,V>
Returns:
a State active when this value map has been modified.

getValueChangeObserver

public final EventObserver getValueChangeObserver()
Returns an Event fired each time a value changes, with a ValueChangeEvent argument.

Specified by:
getValueChangeObserver in interface ValueChangeMap<K,V>
Returns:
an Event fired when a value changes.
See Also:
ValueChangeEvent

notifyValueChange

protected final void notifyValueChange(K key,
                                       V value,
                                       V oldValue,
                                       boolean initialization)

setOriginalValue

protected final void setOriginalValue(K key,
                                      V oldValue)

removeOriginalValue

protected final void removeOriginalValue(K key)

handleValueInitialized

protected void handleValueInitialized(K key,
                                      V value)

handleValueChangedEventInitialized

protected void handleValueChangedEventInitialized()

handleValueRemoved

protected void handleValueRemoved(K key,
                                  V value)
Description copied from class: ValueMapImpl
Called after a value has been removed from this map.

Overrides:
handleValueRemoved in class ValueMapImpl<K,V>
Parameters:
key - the key
value - the value that was removed

handleValueSet

protected void handleValueSet(K key,
                              V value,
                              V previousValue,
                              boolean initialization)
Description copied from class: ValueMapImpl
Called after a value has been set.

Overrides:
handleValueSet in class ValueMapImpl<K,V>
Parameters:
key - the key
value - the value
previousValue - the previous value
initialization - true if the value was being initialized

handleClear

protected void handleClear()
Description copied from class: ValueMapImpl
Called after the value map has been cleared.

Overrides:
handleClear in class ValueMapImpl<K,V>

handleSetAs

protected void handleSetAs(ValueChangeMap<K,V> sourceMap)
Called after the value map has been set.

Parameters:
sourceMap - the source map