TUM CCSM Commons

edu.tum.cs.commons.collections
Class TwoDimHashMap<K1,K2,I>

java.lang.Object
  extended by edu.tum.cs.commons.collections.TwoDimHashMap<K1,K2,I>

public class TwoDimHashMap<K1,K2,I>
extends java.lang.Object

A 2-dimensional hash map. Allows storage of items identified by two different keys. This can be used to store the following data structure:

Version:
$Revision: 26283 $
Author:
Florian Deissenboeck, $Author: juergens $
Rating:
GREEN Hash: 884229989F2777EFC722AAF38C87BBDD

Constructor Summary
TwoDimHashMap()
          Create a new doubly hashed map.
TwoDimHashMap(java.util.Map<K1,java.util.Map<K2,I>> outerMap)
          Create a new doubly hashed using the provided map as outer map.
 
Method Summary
 void clear()
          Clear the whole map.
 boolean containsKey(K1 firstKey, K2 secondKey)
          Returns whether the given key combination is available in the map.
 java.util.Set<K1> getFirstKeys()
          Get all first level keys.
 java.util.Set<K2> getSecondKeys(K1 firstKey)
          Get all the second level keys for a first key.
 int getSecondSize(K1 key1)
          Get the size of the (second) map stored for a first key.
 int getSize()
          Get size of the map.
 I getValue(K1 firstKey, K2 secondKey)
          Get a value by specifying first and second level key.
 java.util.List<I> getValues()
          Get all values stored in the map.
 java.util.Collection<I> getValuesByFirstKey(K1 firstKey)
          Get all values referenced by a first level key.
 java.util.List<I> getValuesBySecondKey(K2 secondKey)
          Get all values referenced by a second level key.
 boolean isEmpty()
          Check if the map is empty.
 void putAll(TwoDimHashMap<K1,K2,I> otherMap)
          Put all values of another TwoDimHashMap into this map.
 void putValue(K1 key1, K2 key2, I value)
          Put a doubly hashed value.
 boolean remove(K1 key)
          Remove all values specified by first key.
 I remove(K1 key1, K2 key2)
          Removes the value associated to the key combination of key1 and key2.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TwoDimHashMap

public TwoDimHashMap()
Create a new doubly hashed map.


TwoDimHashMap

public TwoDimHashMap(java.util.Map<K1,java.util.Map<K2,I>> outerMap)
Create a new doubly hashed using the provided map as outer map.

Method Detail

putAll

public void putAll(TwoDimHashMap<K1,K2,I> otherMap)
Put all values of another TwoDimHashMap into this map.


putValue

public void putValue(K1 key1,
                     K2 key2,
                     I value)
Put a doubly hashed value. Potentially existing value will be overwritten.

Parameters:
key1 - first level key
key2 - second level key
value - the value

getValue

public I getValue(K1 firstKey,
                  K2 secondKey)
Get a value by specifying first and second level key.

Examples:

Parameters:
firstKey - first level key
secondKey - second level key
Returns:
the value. Is null if first or second level key does not exist or if null was explicitly stored.

containsKey

public boolean containsKey(K1 firstKey,
                           K2 secondKey)
Returns whether the given key combination is available in the map.

Example:

Parameters:
firstKey - first level key
secondKey - second level key

getValuesByFirstKey

public java.util.Collection<I> getValuesByFirstKey(K1 firstKey)
Get all values referenced by a first level key.

Examples:

Parameters:
firstKey - the first level key
Returns:
a list of values referenced by the specified first level key

getFirstKeys

public java.util.Set<K1> getFirstKeys()
Get all first level keys. Examples:

Returns:
all first level keys.

getSecondKeys

public java.util.Set<K2> getSecondKeys(K1 firstKey)
Get all the second level keys for a first key. Examples:

Parameters:
firstKey - the first level key.
Returns:
all second level keys for a first level key.

getValuesBySecondKey

public java.util.List<I> getValuesBySecondKey(K2 secondKey)
Get all values referenced by a second level key.

Examples:

Note: This method's complexity is linear in the number of first level keys.

Parameters:
secondKey - the second level key
Returns:
a new list of values referenced by the specified second level key

getValues

public java.util.List<I> getValues()
Get all values stored in the map.

Returns:
a new list of all values.

getSize

public int getSize()
Get size of the map.

Returns:
the number of values stored in this map.

isEmpty

public boolean isEmpty()
Check if the map is empty.


getSecondSize

public int getSecondSize(K1 key1)
Get the size of the (second) map stored for a first key.

Returns:
the size or 0 if key wasn't found.

clear

public void clear()
Clear the whole map.


remove

public I remove(K1 key1,
                K2 key2)
Removes the value associated to the key combination of key1 and key2.

Parameters:
key1 -
key2 -
Returns:
previous value associated with specified key, or null if there was no mapping for key. A null return can also indicate that the map previously associated null with the specified key.

remove

public boolean remove(K1 key)
Remove all values specified by first key.

Parameters:
key - first level key
Returns:
true if key was present, false otherwise

TUM CCSM Commons

TUM CCSM Commons - 2.7