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

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

public class HashMapList<KEY,ITEM>
extends HashMap<KEY,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).

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
HashMapList()
           
 
Method Summary
 void add(KEY key, ITEM item)
          Add a new item at the end of the list under a specific key.
 List<ITEM> get(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.
 List<ITEM> remove(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 List<ITEM> get(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 Map<KEY,List<ITEM>>
Overrides:
get in class HashMap<KEY,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 List<ITEM> remove(Object key)
Remove returns the removed item, if item was non-existent, it returns empty list.

Specified by:
remove in interface Map<KEY,List<ITEM>>
Overrides:
remove in class HashMap<KEY,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:


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