spiffy.core.util
Class TwoDHashMap<K1,K2,V>

java.lang.Object
  extended by spiffy.core.util.TwoDHashMap<K1,K2,V>

public class TwoDHashMap<K1,K2,V>
extends Object

A two-dimensional hashmap, is a HashMap that enables you to refer to values via two keys rather than one. The underlying implementation is simply a HashMap containing HashMap, each of which maps to values.

This is quite useful e.g. when wanting to cache values such as "currency ration" based keys "day of year" and "year".

Author:
Kasper B. Graversen
See Also:
HashMap

Constructor Summary
TwoDHashMap()
           
TwoDHashMap(HashMap<K1,HashMap<K2,V>> map)
           
 
Method Summary
 boolean containsKey(K1 firstKey, K2 secondKey)
          Existence check of a value (or null) mapped to the keys.
 V get(K1 firstKey, K2 secondKey)
          Fetch a value from the Hashmap .
 Set<K1> keySet()
          Returns a set of the keys of the outermost map.
 Object set(K1 firstKey, K2 secondKey, V value)
          Insert a value
 int size()
          Returns the number of key-value mappings in this map for the first key.
 int size(K1 firstKey)
          Returns the number of key-value mappings in this map for the second key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TwoDHashMap

public TwoDHashMap()

TwoDHashMap

public TwoDHashMap(HashMap<K1,HashMap<K2,V>> map)
Method Detail

containsKey

public boolean containsKey(K1 firstKey,
                           K2 secondKey)
Existence check of a value (or null) mapped to the keys.

Parameters:
firstKey - first key
secondKey - second key
Returns:
true when an element (or null) has been stored with the keys

get

public V get(K1 firstKey,
             K2 secondKey)
Fetch a value from the Hashmap .

Parameters:
firstKey - first key
secondKey - second key
Returns:
the element or null.

set

public Object set(K1 firstKey,
                  K2 secondKey,
                  V value)
Insert a value

Parameters:
firstKey - first key
secondKey - second key
value - the value to be inserted. null may be inserted as well.
Returns:
null or the value the insert is replacing.

size

public int size()
Returns the number of key-value mappings in this map for the first key.

Returns:
Returns the number of key-value mappings in this map for the first key.

size

public int size(K1 firstKey)
Returns the number of key-value mappings in this map for the second key.

Returns:
Returns the number of key-value mappings in this map for the second key.

keySet

public Set<K1> keySet()
Returns a set of the keys of the outermost map.