com.groiss.ds
Class TwoLevelMap<K1,K2,V>

java.lang.Object
  extended by com.groiss.ds.TwoLevelMap<K1,K2,V>
All Implemented Interfaces:
Map<K1,Map<K2,V>>

public class TwoLevelMap<K1,K2,V>
extends Object
implements Map<K1,Map<K2,V>>

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.


Nested Class Summary
 
Nested classes/interfaces inherited from interface java.util.Map
Map.Entry<K,V>
 
Constructor Summary
TwoLevelMap()
          Constructs an empty TwoLevelMap.
TwoLevelMap(String name)
          Constructs an empty TwoLevelMap with the specified name.
TwoLevelMap(String name, int initialCapacity)
          Constructs an empty TwoLevelMap with the specified name and initial capacity.
 
Method Summary
 void clear()
           
 boolean containsKey(K1 key1, K2 key2)
          Returns true if this map contains a mapping for the specified key path.
 boolean containsKey(Object key1)
          Returns true if this map contains a mapping for the specified key path component.
 boolean containsKey(Pair<K1,K2> p)
          Returns true if this map contains a mapping for the specified key path designated by the specified Pair
 boolean containsValue(Object value)
           
 Set<Map.Entry<K1,Map<K2,V>>> entrySet()
           
 Set<K1> firstKeySet()
          Deprecated. since 8.0; use keySet()
 V get(K1 key1, K2 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.
 Map<K2,V> get(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.
 V get(Pair<K1,K2> 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.
 boolean isEmpty()
           
 Set<K1> keySet()
           
 Object put(K1 key1, K2 key2, V value)
          Associates the specified value with the specified key path key1 / key2 in this map.
 Map<K2,V> put(K1 key, Map<K2,V> value)
           
 Object put(Pair<K1,K2> p, V value)
          Associates the specified value with the key path designated by the Pair in this map.
 void putAll(Map<? extends K1,? extends Map<K2,V>> t)
           
 Map<K2,V> remove(Object key1)
          Removes the mapping for this key path component from this map if present.
 V remove(Object key1, Object key2)
          Removes the mapping for this key path from this map if present.
 V 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.
 String toString()
           
 Collection<Map<K2,V>> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

TwoLevelMap

public TwoLevelMap()
Constructs an empty TwoLevelMap.


TwoLevelMap

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

Parameters:
name - the name of this map.

TwoLevelMap

public TwoLevelMap(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.
Method Detail

clear

public void clear()
Specified by:
clear in interface Map<K1,Map<K2,V>>

containsKey

public boolean containsKey(K1 key1,
                           K2 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(Object key1)
Returns true if this map contains a mapping for the specified key path component.

Specified by:
containsKey in interface Map<K1,Map<K2,V>>
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(Pair<K1,K2> 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.

containsValue

public boolean containsValue(Object value)
Specified by:
containsValue in interface Map<K1,Map<K2,V>>

entrySet

public Set<Map.Entry<K1,Map<K2,V>>> entrySet()
Specified by:
entrySet in interface Map<K1,Map<K2,V>>

firstKeySet

@Deprecated
public Set<K1> firstKeySet()
Deprecated. since 8.0; use keySet()

Returns:
the first level keyset

get

public V get(K1 key1,
             K2 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 Map<K2,V> get(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.

Specified by:
get in interface Map<K1,Map<K2,V>>
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 V get(Pair<K1,K2> 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)

isEmpty

public boolean isEmpty()
Specified by:
isEmpty in interface Map<K1,Map<K2,V>>

keySet

public Set<K1> keySet()
Specified by:
keySet in interface Map<K1,Map<K2,V>>

put

public Object put(K1 key1,
                  K2 key2,
                  V 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 Map<K2,V> put(K1 key,
                     Map<K2,V> value)
Specified by:
put in interface Map<K1,Map<K2,V>>

put

public Object put(Pair<K1,K2> p,
                  V 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.

putAll

public void putAll(Map<? extends K1,? extends Map<K2,V>> t)
Specified by:
putAll in interface Map<K1,Map<K2,V>>

remove

public Map<K2,V> remove(Object key1)
Removes the mapping for this key path component from this map if present.

Specified by:
remove in interface Map<K1,Map<K2,V>>
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 V remove(Object key1,
                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 V 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.

size

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

Specified by:
size in interface Map<K1,Map<K2,V>>
Returns:
the number of first level key path mappings in this map.

toString

public String toString()
Overrides:
toString in class Object

values

public Collection<Map<K2,V>> values()
Specified by:
values in interface Map<K1,Map<K2,V>>


@enterprise 8.0.10809 Copyright © 2001-2012 Groiss Informatics GmbH. All Rights Reserved.