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

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

public class WeakHashMapMap<PRIMARY_KEY,SECONDARY_KEY,ITEM>
extends java.util.WeakHashMap<PRIMARY_KEY,java.util.Map<SECONDARY_KEY,ITEM>>

Two-level hashMap where the first-level keys are weakly referenced! This means that if the key is not strongly referenced elsewhere, the maps can be garbage collected.


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
WeakHashMapMap()
           
 
Method Summary
 java.util.Map<SECONDARY_KEY,ITEM> get(java.lang.Object primaryKey)
           
 ITEM get(PRIMARY_KEY primaryKey, SECONDARY_KEY secondaryKey)
          Returns the requested item under primary and secondary key.
 ITEM put(PRIMARY_KEY primaryKey, SECONDARY_KEY secondaryKey, ITEM item)
          Inserts item under primary and secondary_key.
 java.util.Map<SECONDARY_KEY,ITEM> remove(java.lang.Object primaryKey)
          removes all items under primaryKey
 ITEM remove(PRIMARY_KEY primaryKey, SECONDARY_KEY secondaryKey)
          removes the item under primary and secondary key.
 
Methods inherited from class java.util.WeakHashMap
clear, containsKey, containsValue, entrySet, isEmpty, keySet, put, putAll, size, values
 
Methods inherited from class java.util.AbstractMap
clone, 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

WeakHashMapMap

public WeakHashMapMap()
Method Detail

get

public java.util.Map<SECONDARY_KEY,ITEM> get(java.lang.Object primaryKey)
Specified by:
get in interface java.util.Map<PRIMARY_KEY,java.util.Map<SECONDARY_KEY,ITEM>>
Overrides:
get in class java.util.WeakHashMap<PRIMARY_KEY,java.util.Map<SECONDARY_KEY,ITEM>>

get

public ITEM get(PRIMARY_KEY primaryKey,
                SECONDARY_KEY secondaryKey)
Returns the requested item under primary and secondary key.

Parameters:
primaryKey - weakly-referenced
secondaryKey -
Returns:
if no such item exists returns NULL

put

public ITEM put(PRIMARY_KEY primaryKey,
                SECONDARY_KEY secondaryKey,
                ITEM item)
Inserts item under primary and secondary_key.

Parameters:
primaryKey - weakly-referenced
secondaryKey -
item -
Returns:
inserted item

remove

public ITEM remove(PRIMARY_KEY primaryKey,
                   SECONDARY_KEY secondaryKey)
removes the item under primary and secondary key.

Parameters:
primaryKey -
secondaryKey -
Returns:
removed item

remove

public java.util.Map<SECONDARY_KEY,ITEM> remove(java.lang.Object primaryKey)
removes all items under primaryKey

Specified by:
remove in interface java.util.Map<PRIMARY_KEY,java.util.Map<SECONDARY_KEY,ITEM>>
Overrides:
remove in class java.util.WeakHashMap<PRIMARY_KEY,java.util.Map<SECONDARY_KEY,ITEM>>
Parameters:
primaryKey -
Returns:
map of all removed items