com.groiss.ds
Class TwoLevelMap

java.lang.Object
  extended by com.groiss.ds.TwoLevelMap

public class TwoLevelMap
extends java.lang.Object

HashMap based two-level Map. A value can be associated with a "key path" which is an ordered list of two keys. It can be also be determined if something has been associated with the first component of a key path irrespective of the concrete second component of the key path.


Constructor Summary
TwoLevelMap()
          Constructs an empty TwoLevelMap.
TwoLevelMap(java.lang.String name)
          Constructs an empty TwoLevelMap with the specified name.
TwoLevelMap(java.lang.String name, int initialCapacity)
          Constructs an empty TwoLevelMap with the specified name and initial capacity.
 
Method Summary
 boolean containsKey(java.lang.Object key1)
          Returns true if this map contains a mapping for the specified key path component.
 boolean containsKey(java.lang.Object key1, java.lang.Object key2)
          Returns true if this map contains a mapping for the specified key path.
 boolean containsKey(Pair p)
          Returns true if this map contains a mapping for the specified key path designated by the specified Pair
 java.util.Set firstKeySet()
           
 java.util.HashMap get(java.lang.Object key1)
          Returns the Map of values to which the specified key path component is mapped in this map, or null if the map contains no mapping for this key path component.
 java.lang.Object get(java.lang.Object key1, java.lang.Object key2)
          Returns the value to which the specified key path is mapped in this map, or null if the map contains no mapping for this key path.
 java.lang.Object get(Pair p)
          Returns the value to which the specified key path designated by the Pair is mapped in this map, or null if the map contains no mapping for this key path.
 java.lang.Object put(java.lang.Object key1, java.lang.Object key2, java.lang.Object value)
          Associates the specified value with the specified key path key1 / key2 in this map.
 java.lang.Object put(Pair p, java.lang.Object value)
          Associates the specified value with the key path designated by the Pair in this map.
 java.util.HashMap remove(java.lang.Object key1)
          Removes the mapping for this key path component from this map if present.
 java.lang.Object remove(java.lang.Object key1, java.lang.Object key2)
          Removes the mapping for this key path from this map if present.
 java.lang.Object remove(Pair p)
          Removes the mapping for the key path designated by the specified Pair from this map if present.
 int size()
          Returns the number of first level key path mappings in this map.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

TwoLevelMap

public TwoLevelMap(java.lang.String name,
                   int initialCapacity)
Constructs an empty TwoLevelMap with the specified name and initial capacity.

Parameters:
name - the name of this map.
initialCapacity - the initial capacity.

TwoLevelMap

public TwoLevelMap(java.lang.String name)
Constructs an empty TwoLevelMap with the specified name.

Parameters:
name - the name of this map.

TwoLevelMap

public TwoLevelMap()
Constructs an empty TwoLevelMap.

Method Detail

put

public java.lang.Object put(java.lang.Object key1,
                            java.lang.Object key2,
                            java.lang.Object value)
Associates the specified value with the specified key path key1 / key2 in this map. If the map previously contained a mapping for this key path, the old value is replaced.

Parameters:
key1 - the first component of the key path with which the specified value is to be associated.
key2 - the second component of the key path with which the specified value is to be associated.
value - value to be associated with the specified key path.
Returns:
previous value associated with specified key path, or null if there was no mapping for key path. A null return can also indicate that the HashMap previously associated null with the specified key.

put

public java.lang.Object put(Pair p,
                            java.lang.Object value)
Associates the specified value with the key path designated by the Pair in this map. If the map previously contained a mapping for this key path, the old value is replaced.

Parameters:
p - the Pair designating the key path p.first() designated the first path component, p.second() designates the second path component
value - value to be associated with the specified key path.
Returns:
previous value associated with specified key path, or null if there was no mapping for key path. A null return can also indicate that the HashMap previously associated null with the specified key.

get

public java.util.HashMap get(java.lang.Object key1)
Returns the Map of values to which the specified key path component is mapped in this map, or null if the map contains no mapping for this key path component. A return value of null does not necessarily indicate that the map contains no mapping for the key path component; it is also possible that the map explicitly maps the key path component to null. The containsKey method may be used to distinguish these two cases.

Parameters:
key1 - the first component of the key path whose associated map is to be returned.
Returns:
the value to which this map maps the specified key path component, or null if the map contains no mapping for this key path component.
See Also:
put(Object, Object, Object)

get

public java.lang.Object get(java.lang.Object key1,
                            java.lang.Object key2)
Returns the value to which the specified key path is mapped in this map, or null if the map contains no mapping for this key path. A return value of null does not necessarily indicate that the map contains no mapping for the key path ; it is also possible that the map explicitly maps the key path to null. The containsKey method may be used to distinguish these two cases.

Parameters:
key1 - the first component of the key path whose associated map is to be returned.
key2 - the second component of the key path whose associated map is to be returned.
Returns:
the value to which this map maps the specified key path, or null if the map contains no mapping for this key path.
See Also:
put(Object, Object, Object)

get

public java.lang.Object get(Pair p)
Returns the value to which the specified key path designated by the Pair is mapped in this map, or null if the map contains no mapping for this key path. A return value of null does not necessarily indicate that the map contains no mapping for the key path ; it is also possible that the map explicitly maps the key path to null. The containsKey method may be used to distinguish these two cases.

Parameters:
p - the Pair designating the key path p.first designated the first path component, p.second designates the second path component
Returns:
the value to which this map maps the specified key path, or null if the map contains no mapping for this key path.
See Also:
put(Pair, Object)

containsKey

public boolean containsKey(java.lang.Object key1)
Returns true if this map contains a mapping for the specified key path component.

Parameters:
key1 - The first part of the key path whose presence in this map is to be tested
Returns:
true if this map contains a mapping for the specified key path component.

containsKey

public boolean containsKey(java.lang.Object key1,
                           java.lang.Object key2)
Returns true if this map contains a mapping for the specified key path.

Parameters:
key1 - The first part of the key path whose presence in this map is to be tested
key2 - The second part of the key path whose presence in this map is to be tested
Returns:
true if this map contains a mapping for the specified key path.

containsKey

public boolean containsKey(Pair p)
Returns true if this map contains a mapping for the specified key path designated by the specified Pair

Parameters:
p - the Pair designating the key path p.first designated the first path component, p.second designates the second path component
Returns:
true if this map contains a mapping for the specified key path.

remove

public java.util.HashMap remove(java.lang.Object key1)
Removes the mapping for this key path component from this map if present.

Parameters:
key1 - key path component whose mapping is to be removed from the map.
Returns:
previous Map associated with specified key path component , or null if there was no mapping for key1. A null return can also indicate that the map previously associated null with the specified key.

remove

public java.lang.Object remove(java.lang.Object key1,
                               java.lang.Object key2)
Removes the mapping for this key path from this map if present.

Parameters:
key1 - the first component of the key path whose mapping is to be removed from the map.
key2 - the second component of the key path whose mapping is to be removed from the map.
Returns:
previous value associated with specified key path, or null if there was no mapping for the key path. A null return can also indicate that the value previously associated null with the specified key path.

remove

public java.lang.Object remove(Pair p)
Removes the mapping for the key path designated by the specified Pair from this map if present.

Parameters:
p - the Pair designating the key path p.first designated the first path component, p.second designates the second path component
Returns:
previous value associated with specified key path, or null if there was no mapping for the key path. A null return can also indicate that the value previously associated null with the specified key path.

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

size

public int size()
Returns the number of first level key path mappings in this map.

Returns:
the number of first level key path mappings in this map.

firstKeySet

public java.util.Set firstKeySet()


Copyright © 2001-2006 Groiss Informatics GmbH. All Rights Reserved.