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

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

public abstract class LazyMapMap<PRIMARY_KEY,SECONDARY_KEY,ITEM>
extends java.util.HashMap<PRIMARY_KEY,java.util.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).

See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.util.AbstractMap
java.util.AbstractMap.SimpleEntry<K,V>, java.util.AbstractMap.SimpleImmutableEntry<K,V>
 
Constructor Summary
LazyMapMap()
           
 
Method Summary
protected abstract  ITEM create(SECONDARY_KEY key)
          Creates value for given key.
 java.util.Map<SECONDARY_KEY,ITEM> get(java.lang.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.
 java.util.Map<SECONDARY_KEY,ITEM> remove(java.lang.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

LazyMapMap

public LazyMapMap()
Method Detail

create

protected abstract ITEM create(SECONDARY_KEY key)
Creates value for given key.

Parameters:
key -
Returns:

get

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

Specified by:
get in interface java.util.Map<PRIMARY_KEY,java.util.Map<SECONDARY_KEY,ITEM>>
Overrides:
get in class java.util.HashMap<PRIMARY_KEY,java.util.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 java.util.Map<SECONDARY_KEY,ITEM> remove(java.lang.Object primaryKey)
Remove returns the removed item, if item was non-existent, it returns empty map.

Specified by:
remove in interface java.util.Map<PRIMARY_KEY,java.util.Map<SECONDARY_KEY,ITEM>>
Overrides:
remove in class java.util.HashMap<PRIMARY_KEY,java.util.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: