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

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

public class HashMapList<KEY,ITEM>
extends java.util.HashMap<KEY,java.util.List<ITEM>>

Map containing lists of items. Whenever a list under some key is requested and does not exists, the HashMapList automatically creates new one.

The implementation is unsynchronized, created lists are synchronized (just iteration over list 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
HashMapList()
           
 
Method Summary
 void add(KEY key, ITEM item)
          Add a new item at the end of the list under a specific key.
 java.util.List<ITEM> get(java.lang.Object key)
          Returns a list under a specific key in the map.
 ITEM peek(KEY key)
          Returns first item from the list under a specific key.
 ITEM pull(KEY key)
          Removes first item from the list under a specific key.
 ITEM remove(KEY key, int index)
          Remove an item at 'index' from the list under a specific key.
 java.util.List<ITEM> remove(java.lang.Object key)
          Remove returns the removed item, if item was non-existent, it returns empty list.
 
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

HashMapList

public HashMapList()
Method Detail

get

public java.util.List<ITEM> get(java.lang.Object key)
Returns a list under a specific key in the map. If list does not exist, it automatically creates new (synchronized) one, inserts it into map and returns it.

Specified by:
get in interface java.util.Map<KEY,java.util.List<ITEM>>
Overrides:
get in class java.util.HashMap<KEY,java.util.List<ITEM>>

add

public void add(KEY key,
                ITEM item)
Add a new item at the end of the list under a specific key. If list does not exists, it automatically creates new (synchronized) one.

Parameters:
key -
item -

remove

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

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

remove

public ITEM remove(KEY key,
                   int index)
Remove an item at 'index' from the list under a specific key. The list bounds are not checked.

Parameters:
key -
index -
Returns:

peek

public ITEM peek(KEY key)
Returns first item from the list under a specific key. If the list is empty, returns null.

Parameters:
key -
Returns:

pull

public ITEM pull(KEY key)
Removes first item from the list under a specific key.

Parameters:
key -
Returns: