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

java.lang.Object
  extended by org.jminor.common.model.valuemap.ValueMapImpl<K,V>
Type Parameters:
K - the key type
V - the value type
All Implemented Interfaces:
ValueAsStringProvider<K>, ValueCollectionProvider<V>, ValueMap<K,V>, ValueProvider<K,V>
Direct Known Subclasses:
ValueChangeMapImpl

public class ValueMapImpl<K,V>
extends Object
implements ValueMap<K,V>

A default ValueMap implementation.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.jminor.common.model.valuemap.ValueMap
ValueMap.ToString<K>
 
Constructor Summary
ValueMapImpl()
           
 
Method Summary
 void clear()
          Removes all values from this map.
 boolean containsValue(K key)
          Returns true if this ValueMap contains a value for the given key, that value can be null.
 V copyValue(V value)
          Returns a deep copy of the given value, immutable values are simply returned.
 boolean equals(Object obj)
          Two ValueMapImpl objects are equal if they contain the same number of values and all their values are equal.
 V getValue(K key)
          Retrieves the value mapped to the given key
 String getValueAsString(K key)
          Retrieves the value mapped to the given key as a String
 Collection<K> getValueKeys()
          
 Collection<V> getValues()
          Retrieves the values associated with this value provider.
protected  void handleClear()
          Called after the value map has been cleared.
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.
 int hashCode()
          
 boolean isValueNull(K key)
          Returns true if a null value is mapped to the given key.
 V removeValue(K key)
          Removes the given key and value from this value map along with the original value if any.
 V setValue(K key, V value)
          Maps the given value to the given key, returning the old value if any.
 int size()
          
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ValueMapImpl

public ValueMapImpl()
Method Detail

isValueNull

public boolean isValueNull(K key)
Returns true if a null value is mapped to the given key.

Specified by:
isValueNull in interface ValueMap<K,V>
Parameters:
key - the key
Returns:
true if the value mapped to the given key is null

setValue

public V setValue(K key,
                  V value)
Maps the given value to the given key, returning the old value if any.

Specified by:
setValue in interface ValueMap<K,V>
Parameters:
key - the key
value - the value
Returns:
the previous value mapped to the given key, null if no such value existed

getValue

public V getValue(K key)
Retrieves the value mapped to the given key

Specified by:
getValue in interface ValueProvider<K,V>
Parameters:
key - the key
Returns:
the value mapped to the given key, null if no such mapping exists

getValueAsString

public String getValueAsString(K key)
Retrieves the value mapped to the given key as a String

Specified by:
getValueAsString in interface ValueAsStringProvider<K>
Parameters:
key - the key
Returns:
the value mapped to the given key as a string, an empty string if no such mapping exists

copyValue

public V copyValue(V value)
Returns a deep copy of the given value, immutable values are simply returned.

Specified by:
copyValue in interface ValueMap<K,V>
Parameters:
value - the value to copy
Returns:
a deep copy of the given value, or the same instance in case the value is immutable

equals

public boolean equals(Object obj)
Two ValueMapImpl objects are equal if they contain the same number of values and all their values are equal.

Overrides:
equals in class Object

hashCode

public int hashCode()

Overrides:
hashCode in class Object

containsValue

public final boolean containsValue(K key)
Returns true if this ValueMap contains a value for the given key, that value can be null.

Specified by:
containsValue in interface ValueMap<K,V>
Parameters:
key - the key
Returns:
true if a value is mapped to this key

removeValue

public final V removeValue(K key)
Removes the given key and value from this value map along with the original value if any. If no value is mapped to the given key, this method has no effect.

Specified by:
removeValue in interface ValueMap<K,V>
Parameters:
key - the key to remove
Returns:
the value that was removed

getValueKeys

public final Collection<K> getValueKeys()

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

clear

public final void clear()
Removes all values from this map.

Specified by:
clear in interface ValueMap<K,V>

size

public final int size()

Specified by:
size in interface ValueMap<K,V>
Returns:
the number of values in this map

getValues

public final Collection<V> getValues()
Retrieves the values associated with this value provider.

Specified by:
getValues in interface ValueCollectionProvider<V>
Specified by:
getValues in interface ValueMap<K,V>
Returns:
an unmodifiable view of the values in this map.

handleValueSet

protected void handleValueSet(K key,
                              V value,
                              V previousValue,
                              boolean initialization)
Called after a value has been set.

Parameters:
key - the key
value - the value
previousValue - the previous value
initialization - true if the value was being initialized

handleValueRemoved

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

Parameters:
key - the key
value - the value that was removed

handleClear

protected void handleClear()
Called after the value map has been cleared.