pl.edu.agh.cast.util
Class MultiMap<K,V>

java.lang.Object
  extended by pl.edu.agh.cast.util.MultiMap<K,V>

public class MultiMap<K,V>
extends java.lang.Object

This class implements a multi-map functionality. Multi-map is a map which allows for multiple values to be kept under one key. This implementation (by default) uses HashMap with LinkedLists, however different Map implementation may be provided during construction. WARNING: This collection does not implement Collection interface and is not in the Java Collections hierarchy.

Author:
tmilos

Constructor Summary
MultiMap()
          Creates new instance using HashMap as underlying map.
MultiMap(boolean allowDuplicates)
          Creates new instance using HashMap as underlying map.
MultiMap(java.util.Map<K,java.util.List<V>> map)
          Creates new instance using map as underlying map.
MultiMap(java.util.Map<K,java.util.List<V>> map, boolean allowDuplicates)
          Creates new instance using map as underlying map.
 
Method Summary
 boolean equals(java.lang.Object obj)
           
 java.util.List<V> get(K key)
          Returns a (modifiable) list of values stored under given key.
 java.util.Map<K,java.util.List<V>> getMap()
          Returns an unmodifiable view of the underlying map.
 boolean isAllowDuplicates()
          Checks if duplicate values are allowed for one key.
 java.util.List<V> put(K key, V... values)
          Adds values to the key entry.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

MultiMap

public MultiMap()
Creates new instance using HashMap as underlying map. No duplicate values for single key are allowed.


MultiMap

public MultiMap(boolean allowDuplicates)
Creates new instance using HashMap as underlying map. Duplicate values for single key are allowed if allowDuplicates is true.

Parameters:
allowDuplicates - if true than duplicate values are allowed for one key. Defaults to false

MultiMap

public MultiMap(java.util.Map<K,java.util.List<V>> map)
Creates new instance using map as underlying map. No duplicate values for single key are allowed.

Parameters:
map - the underlying map

MultiMap

public MultiMap(java.util.Map<K,java.util.List<V>> map,
                boolean allowDuplicates)
Creates new instance using map as underlying map. Duplicate values for single key are allowed if allowDuplicates is true.

Parameters:
map - the underlying map
allowDuplicates - if true than duplicate values are allowed for one key. Defaults to false
Method Detail

getMap

public java.util.Map<K,java.util.List<V>> getMap()
Returns an unmodifiable view of the underlying map. However, the lists that are the values of the map are modifiable.

Returns:
unmodifiable view of the underlying map

put

public java.util.List<V> put(K key,
                             V... values)
Adds values to the key entry. Behavior may differ depending on the isAllowDuplicates() value.

Parameters:
key - the key
values - the values to add
Returns:

get

public java.util.List<V> get(K key)
Returns a (modifiable) list of values stored under given key.

Parameters:
key - the key
Returns:
list of values

isAllowDuplicates

public boolean isAllowDuplicates()
Checks if duplicate values are allowed for one key.


equals

public boolean equals(java.lang.Object obj)
Overrides:
equals in class java.lang.Object


Copyright © 2007-2008 AGH University of Science and Technology. All Rights Reserved.