org.eigenbase.util
Class MultiMap<K,V>

java.lang.Object
  extended by org.eigenbase.util.MultiMap<K,V>

public class MultiMap<K,V>
extends Object

Map which contains more than one value per key.

You can either use a MultiMap as a regular map, or you can use the additional methods putMulti(K, V) and getMulti(K). Values are returned in the order in which they were added.

TODO jvs 21-Jul-2007: unit test for this class

Since:
May 18, 2003
Version:
$Id: //open/dev/farrago/src/org/eigenbase/util/MultiMap.java#16 $
Author:
jhyde

Nested Class Summary
private  class MultiMap.EntryIter
          Implementation for entryIterMulti().
private static class MultiMap.ValueList<V>
          Holder class, ensures that user's values are never interpreted as multiple values.
 
Field Summary
private  Map<K,Object> map
           
 
Constructor Summary
MultiMap()
           
 
Method Summary
 void clear()
           
 boolean containsKey(K key)
           
 MultiMap.EntryIter entryIterMulti()
          Like entrySet().iterator(), but returns one Map.Entry per value rather than one per key.
private  Object get(K key)
           
 List<V> getMulti(K key)
          Returns a list of values for a given key; returns an empty list if not found.
private  Object put(K key, V value)
           
 void putMulti(K key, V value)
          Adds a value for this key.
 Object remove(K key)
           
 boolean removeMulti(K key, V value)
          Removes a value for this key.
 int size()
          Returns the number of keys in this MultiMap.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

map

private final Map<K,Object> map
Constructor Detail

MultiMap

public MultiMap()
Method Detail

size

public int size()
Returns the number of keys in this MultiMap.

Returns:
number of keys in this MultiMap

get

private Object get(K key)

put

private Object put(K key,
                   V value)

getMulti

public List<V> getMulti(K key)
Returns a list of values for a given key; returns an empty list if not found.

"Postcondition:"
return != null

putMulti

public void putMulti(K key,
                     V value)
Adds a value for this key.


removeMulti

public boolean removeMulti(K key,
                           V value)
Removes a value for this key.


entryIterMulti

public MultiMap.EntryIter entryIterMulti()
Like entrySet().iterator(), but returns one Map.Entry per value rather than one per key.


remove

public Object remove(K key)

containsKey

public boolean containsKey(K key)

clear

public void clear()