de.matthiasmann.twl.utils
Class CascadedHashMap<K,V>

java.lang.Object
  extended by de.matthiasmann.twl.utils.CascadedHashMap<K,V>
Type Parameters:
K - the key type
V - the value type

public class CascadedHashMap<K,V>
extends java.lang.Object

An add only hash map which support for a fallback hash map.

The primary use for this class is to store hierarchic data structures.


Nested Class Summary
protected static class CascadedHashMap.Entry<K,V>
           
 
Constructor Summary
CascadedHashMap()
           
 
Method Summary
 void collapseAndSetFallback(CascadedHashMap<K,V> map)
          Collapses the existing fallback (by copying it into this map) and sets a new fallback map.
 V get(K key)
          Retrieves a value from this map or it's fallback map when present.
protected static
<K,V> CascadedHashMap.Entry<K,V>
getEntry(CascadedHashMap<K,V> map, K key)
           
 V put(K key, V value)
          Puts an entry into this map
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

CascadedHashMap

public CascadedHashMap()
Method Detail

get

public V get(K key)
Retrieves a value from this map or it's fallback map when present.

Parameters:
key - the key to lookup
Returns:
the value or null when not found

put

public V put(K key,
             V value)
Puts an entry into this map

Parameters:
key - the key
value - the value
Returns:
the old (replaced) value or null if no entry was replaced
Throws:
java.lang.NullPointerException - when key is null

collapseAndSetFallback

public void collapseAndSetFallback(CascadedHashMap<K,V> map)
Collapses the existing fallback (by copying it into this map) and sets a new fallback map.

Parameters:
map -

getEntry

protected static <K,V> CascadedHashMap.Entry<K,V> getEntry(CascadedHashMap<K,V> map,
                                                           K key)