TUM CCSM Commons

edu.tum.cs.commons.collections
Class HashedListMap<K,I>

java.lang.Object
  extended by edu.tum.cs.commons.collections.HashedListMap<K,I>
Direct Known Subclasses:
UnmodifiableHashedListMap

public class HashedListMap<K,I>
extends java.lang.Object

This class defines a mapping from on item to a list of items.

Version:
$Revision: 29486 $
Author:
Florian Deissenboeck, $Author: juergens $
Rating:
GREEN Hash: 9C7E831BF9AF4EA0F4F0871B02C36449

Constructor Summary
HashedListMap()
          Create new hashed list map.
HashedListMap(HashedListMap<K,I> other)
          Copy constructor.
HashedListMap(java.util.Map<K,java.util.List<I>> map)
          Create new hashed list map with a specified map.
 
Method Summary
 void add(K key, I item)
          Add an item to the list identified by a key.
 void addAll(HashedListMap<K,I> other)
          Adds all elements from another hashed list map.
 void addAll(K key, java.util.Collection<I> items)
          Add all items to the list identified by a key.
 boolean areAllListsEmpty()
          Checks if all lists stored in the map are empty.
 void clear()
          Clear map.
 boolean containsList(K key)
          Check if a list is present for a given key.
 java.util.List<I> createList(K key)
          Create an empty list for a key.
 java.util.Set<K> getKeys()
          Get keys.
 java.util.List<I> getList(K key)
          Get list for key.
 java.util.List<I> getValues()
          Return all values from all lists.
 java.util.Map<K,I[]> listsToArrays(java.lang.Class<I> type)
          Converts the HashedListMap to a map with arrays
 void removeAllLists(java.util.Collection<K> keys)
          Removes the lists stored for a collection of keys
 void removeList(K key)
          Removes the list stored for a key.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

HashedListMap

public HashedListMap()
Create new hashed list map.


HashedListMap

public HashedListMap(java.util.Map<K,java.util.List<I>> map)
Create new hashed list map with a specified map.


HashedListMap

public HashedListMap(HashedListMap<K,I> other)
Copy constructor.

Method Detail

createList

public java.util.List<I> createList(K key)
Create an empty list for a key. This overrides a previosly mapped list.


getList

public java.util.List<I> getList(K key)
Get list for key.

Returns:
the list or null

add

public void add(K key,
                I item)
Add an item to the list identified by a key.


addAll

public void addAll(K key,
                   java.util.Collection<I> items)
Add all items to the list identified by a key.


addAll

public void addAll(HashedListMap<K,I> other)
Adds all elements from another hashed list map.


containsList

public boolean containsList(K key)
Check if a list is present for a given key.


removeList

public void removeList(K key)
Removes the list stored for a key.


removeAllLists

public void removeAllLists(java.util.Collection<K> keys)
Removes the lists stored for a collection of keys


getKeys

public java.util.Set<K> getKeys()
Get keys.


getValues

public java.util.List<I> getValues()
Return all values from all lists.


areAllListsEmpty

public boolean areAllListsEmpty()
Checks if all lists stored in the map are empty. This returns true if getValues() returns an empty list.


clear

public void clear()
Clear map. This removes all lists.


listsToArrays

public java.util.Map<K,I[]> listsToArrays(java.lang.Class<I> type)
Converts the HashedListMap to a map with arrays

Parameters:
type - Type of the target array

TUM CCSM Commons

TUM CCSM Commons - 2.7