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

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

public class TwoLevelMap<K1,K2,V>
extends java.lang.Object
implements java.util.Map<K1,java.util.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
java.util.Map.Entry<K,V>
 
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
 void clear()
           
 boolean containsKey(K1 key1, K2 key2)
          Returns true if this map contains a mapping for the specified key path.
 boolean containsKey(java.lang.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(java.lang.Object value)
           
 java.util.Set<java.util.Map.Entry<K1,java.util.Map<K2,V>>> entrySet()
           
 java.util.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.
 java.util.Map<K2,V> 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.
 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()
           
 java.util.Set<K1> keySet()
           
 java.lang.Object put(K1 key1, K2 key2, V value)
          Associates the specified value with the specified key path key1 / key2 in this map.
 java.util.Map<K2,V> put(K1 key, java.util.Map<K2,V> value)
           
 java.lang.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(java.util.Map<? extends K1,? extends java.util.Map<K2,V>> t)
           
 java.util.Map<K2,V> remove(java.lang.Object key1)
          Removes the mapping for this key path component 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.
 V removeByKeys(java.lang.Object key1, java.lang.Object key2)
          Removes the mapping for this key path from this map if present.
 int size()
          Returns the number of first level key path mappings in this map.
 java.lang.String toString()
           
 java.util.Collection<java.util.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(java.lang.String name)
Constructs an empty TwoLevelMap with the specified name.

Parameters:
name - the name of this map.

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.
Method Detail

clear

public void clear()
Specified by:
clear in interface java.util.Map<K1,java.util.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(java.lang.Object key1)
Returns true if this map contains a mapping for the specified key path component.

Specified by:
containsKey in interface java.util.Map<K1,java.util.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(java.lang.Object value)
Specified by:
containsValue in interface java.util.Map<K1,java.util.Map<K2,V>>

entrySet

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

firstKeySet

@Deprecated
public java.util.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 java.util.Map<K2,V> 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.

Specified by:
get in interface java.util.Map<K1,java.util.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 java.util.Map<K1,java.util.Map<K2,V>>

keySet

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

put

public java.lang.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 java.util.Map<K2,V> put(K1 key,
                               java.util.Map<K2,V> value)
Specified by:
put in interface java.util.Map<K1,java.util.Map<K2,V>>

put

public java.lang.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(java.util.Map<? extends K1,? extends java.util.Map<K2,V>> t)
Specified by:
putAll in interface java.util.Map<K1,java.util.Map<K2,V>>

remove

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

Specified by:
remove in interface java.util.Map<K1,java.util.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.

removeByKeys

public V removeByKeys(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.
Since:
(July 2015); formerly this method has been named remove. Renamed because of clash with new method in Java 8.

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 java.util.Map<K1,java.util.Map<K2,V>>
Returns:
the number of first level key path mappings in this map.

toString

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

values

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


@enterprise 8.0.22989 Copyright © 2001-2017 Groiss Informatics GmbH. All Rights Reserved.