cz.cuni.amis.utils.maps
Class HashMapMap<PRIMARY_KEY,SECONDARY_KEY,ITEM>

Package class diagram package HashMapMap
java.lang.Object
  extended by java.util.AbstractMap<K,V>
      extended by java.util.HashMap<PRIMARY_KEY,Map<SECONDARY_KEY,ITEM>>
          extended by cz.cuni.amis.utils.maps.HashMapMap<PRIMARY_KEY,SECONDARY_KEY,ITEM>
Type Parameters:
PRIMARY_KEY -
SECONDARY_KEY -
ITEM -
All Implemented Interfaces:
Serializable, Cloneable, Map<PRIMARY_KEY,Map<SECONDARY_KEY,ITEM>>

public class HashMapMap<PRIMARY_KEY,SECONDARY_KEY,ITEM>
extends HashMap<PRIMARY_KEY,Map<SECONDARY_KEY,ITEM>>

Map containing other maps. Whenever a map under some key is requested and does not exists, the HashMapMap automatically creates new one.

The implementation is unsynchronized, created maps are synchronized (just iteration over the inner-map must be synchronized by the user as described in Java(tm) documentation).

Author:
Jimmy
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
HashMapMap()
           
HashMapMap(int primaryCapacity, int secondaryCapacity)
           
 
Method Summary
 Map<SECONDARY_KEY,ITEM> get(Object primaryKey)
          The get method ensures that the requested map under primaryKey always exists!
 ITEM get(PRIMARY_KEY primaryKey, SECONDARY_KEY secondaryKey)
          Returns an item under primary and secondary key if exists (otherwise a null is returned).
 void put(PRIMARY_KEY primaryKey, SECONDARY_KEY secondaryKey, ITEM item)
          Inserts an item under primary and then secondary key.
 Map<SECONDARY_KEY,ITEM> remove(Object primaryKey)
          Remove returns the removed item, if item was non-existent, it returns empty map.
 ITEM remove(PRIMARY_KEY primaryKey, SECONDARY_KEY secondaryKey)
          Removes an item from the map.
 
Methods inherited from class java.util.HashMap
clear, clone, containsKey, containsValue, entrySet, isEmpty, keySet, put, putAll, size, values
 
Methods inherited from class java.util.AbstractMap
equals, hashCode, toString
 
Methods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface java.util.Map
equals, hashCode
 

Constructor Detail

HashMapMap

public HashMapMap()

HashMapMap

public HashMapMap(int primaryCapacity,
                  int secondaryCapacity)
Method Detail

get

public Map<SECONDARY_KEY,ITEM> get(Object primaryKey)
The get method ensures that the requested map under primaryKey always exists!

Specified by:
get in interface Map<PRIMARY_KEY,Map<SECONDARY_KEY,ITEM>>
Overrides:
get in class HashMap<PRIMARY_KEY,Map<SECONDARY_KEY,ITEM>>
Parameters:
primaryKey - must be instance of PRIMARY_KEY

get

public ITEM get(PRIMARY_KEY primaryKey,
                SECONDARY_KEY secondaryKey)
Returns an item under primary and secondary key if exists (otherwise a null is returned).

Parameters:
primaryKey -
secondaryKey -
Returns:

put

public void put(PRIMARY_KEY primaryKey,
                SECONDARY_KEY secondaryKey,
                ITEM item)
Inserts an item under primary and then secondary key.

Parameters:
primaryKey -
secondaryKey -
item -

remove

public Map<SECONDARY_KEY,ITEM> remove(Object primaryKey)
Remove returns the removed item, if item was non-existent, it returns empty map.

Specified by:
remove in interface Map<PRIMARY_KEY,Map<SECONDARY_KEY,ITEM>>
Overrides:
remove in class HashMap<PRIMARY_KEY,Map<SECONDARY_KEY,ITEM>>
Parameters:
primaryKey -
Returns:

remove

public ITEM remove(PRIMARY_KEY primaryKey,
                   SECONDARY_KEY secondaryKey)
Removes an item from the map.

Parameters:
primaryKey -
secondaryKey -
Returns:


Copyright © 2013 AMIS research group, Faculty of Mathematics and Physics, Charles University in Prague, Czech Republic. All Rights Reserved.