cz.cuni.amis.utils.maps
Class HashMapSet<KEY,ITEM>

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

public class HashMapSet<KEY,ITEM>
extends java.util.HashMap<KEY,java.util.Set<ITEM>>

Map containing sets. Whenever a set under some key is requested and does not exists, the HashMapSet automatically creates new one.

The implementation is unsynchronized, created sets are synchronized (just iteration over the set 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
HashMapSet()
           
 
Method Summary
 void add(KEY key, ITEM item)
          Adds the item into the set under the key.
 boolean contains(KEY key, ITEM item)
          Tests whether an 'item' is inside the set under 'key'.
 java.util.Set<ITEM> get(java.lang.Object primaryKey)
          The get method ensures that the requested set under primaryKey always exists!
 boolean remove(KEY key, ITEM item)
          Removes the item from the set under the key.
 java.util.Set<ITEM> remove(java.lang.Object key)
          Remove returns the removed item, if item was non-existent, it returns empty set.
 
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

HashMapSet

public HashMapSet()
Method Detail

get

public java.util.Set<ITEM> get(java.lang.Object primaryKey)
The get method ensures that the requested set under primaryKey always exists!

Specified by:
get in interface java.util.Map<KEY,java.util.Set<ITEM>>
Overrides:
get in class java.util.HashMap<KEY,java.util.Set<ITEM>>
Parameters:
primaryKey - must be instance of PRIMARY_KEY

add

public void add(KEY key,
                ITEM item)
Adds the item into the set under the key.

Parameters:
key -
item -

remove

public java.util.Set<ITEM> remove(java.lang.Object key)
Remove returns the removed item, if item was non-existent, it returns empty set.

Specified by:
remove in interface java.util.Map<KEY,java.util.Set<ITEM>>
Overrides:
remove in class java.util.HashMap<KEY,java.util.Set<ITEM>>
Parameters:
primaryKey -
Returns:

remove

public boolean remove(KEY key,
                      ITEM item)
Removes the item from the set under the key.

Parameters:
key -
item -

contains

public boolean contains(KEY key,
                        ITEM item)
Tests whether an 'item' is inside the set under 'key'.

Parameters:
key -
item -
Returns: