edu.stanford.nlp.util
Class TwoDimensionalCollectionValuedMap<K1,K2,V>

java.lang.Object
  extended by edu.stanford.nlp.util.TwoDimensionalCollectionValuedMap<K1,K2,V>
All Implemented Interfaces:
java.io.Serializable

public class TwoDimensionalCollectionValuedMap<K1,K2,V>
extends java.lang.Object
implements java.io.Serializable

A class which can store mappings from Object keys to Collections of Object values. Important methods are the add(K1, K2, V) and for adding a value to/from the Collection associated with the key, and the get(K1, K2) method for getting the Collection associated with a key. The class is quite general, because on construction, it is possible to pass a MapFactory which will be used to create the underlying map and a CollectionFactory which will be used to create the Collections. Thus this class can be configured to act like a "HashSetValuedMap" or a "ListValuedMap", or even a "HashSetValuedIdentityHashMap". The possibilities are endless!

Author:
Teg Grenager (grenager@cs.stanford.edu)
See Also:
Serialized Form

Field Summary
protected  CollectionFactory<V> cf
           
protected  MapFactory<K2,java.util.Collection<V>> mf
           
 
Constructor Summary
TwoDimensionalCollectionValuedMap()
          Creates a new empty TwoDimensionalCollectionValuedMap which uses a HashMap as the underlying Map, and HashSets as the Collections in each mapping.
TwoDimensionalCollectionValuedMap(CollectionFactory<V> cf)
          Creates a new empty TwoDimensionalCollectionValuedMap which uses a HashMap as the underlying Map.
TwoDimensionalCollectionValuedMap(MapFactory<K2,java.util.Collection<V>> mf, CollectionFactory<V> cf)
          Creates a new empty TwoDimensionalCollectionValuedMap.
TwoDimensionalCollectionValuedMap(MapFactory<K2,java.util.Collection<V>> mf, CollectionFactory<V> cf, boolean treatCollectionsAsImmutable)
          Creates a new empty TwoDimensionalCollectionValuedMap.
 
Method Summary
 void add(K1 key1, K2 key2, java.util.Collection<V> value)
          Adds a collection of values to the Collection mapped to by the key.
 void add(K1 key1, K2 key2, V value)
          Adds the value to the Collection mapped to by the key.
 void addKey(K1 key1)
          yes, this is a weird method, but i need it.
 void clear()
           
 boolean containsKey(K1 key)
           
 java.util.Set<java.util.Map.Entry<K1,CollectionValuedMap<K2,V>>> entrySet()
           
 java.util.Set<K1> firstKeySet()
           
 java.util.Collection<V> get(K1 key1, K2 key2)
           
 CollectionValuedMap<K2,V> getCollectionValuedMap(K1 key1)
           
 java.util.Set<K1> keySet()
           
 void retainAll(java.util.Set<K1> keys)
           
 java.util.Set<K2> secondKeySet()
           
 java.lang.String toString()
           
 java.util.Collection<V> values()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

mf

protected MapFactory<K2,java.util.Collection<V>> mf

cf

protected CollectionFactory<V> cf
Constructor Detail

TwoDimensionalCollectionValuedMap

public TwoDimensionalCollectionValuedMap()
Creates a new empty TwoDimensionalCollectionValuedMap which uses a HashMap as the underlying Map, and HashSets as the Collections in each mapping. Does not treat Collections as immutable.


TwoDimensionalCollectionValuedMap

public TwoDimensionalCollectionValuedMap(CollectionFactory<V> cf)
Creates a new empty TwoDimensionalCollectionValuedMap which uses a HashMap as the underlying Map. Does not treat Collections as immutable.

Parameters:
cf - a CollectionFactory which will be used to generate the Collections in each mapping

TwoDimensionalCollectionValuedMap

public TwoDimensionalCollectionValuedMap(MapFactory<K2,java.util.Collection<V>> mf,
                                         CollectionFactory<V> cf)
Creates a new empty TwoDimensionalCollectionValuedMap. Does not treat Collections as immutable.

Parameters:
mf - a MapFactory which will be used to generate the underlying Map
cf - a CollectionFactory which will be used to generate the Collections in each mapping

TwoDimensionalCollectionValuedMap

public TwoDimensionalCollectionValuedMap(MapFactory<K2,java.util.Collection<V>> mf,
                                         CollectionFactory<V> cf,
                                         boolean treatCollectionsAsImmutable)
Creates a new empty TwoDimensionalCollectionValuedMap.

Parameters:
mf - a MapFactory which will be used to generate the underlying Map
cf - a CollectionFactory which will be used to generate the Collections in each mapping
treatCollectionsAsImmutable - if true, forces this Map to create new a Collection everytime a new value is added to or deleted from the Collection a mapping.
Method Detail

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getCollectionValuedMap

public CollectionValuedMap<K2,V> getCollectionValuedMap(K1 key1)
Returns:
the Collection mapped to by key, never null, but may be empty.

get

public java.util.Collection<V> get(K1 key1,
                                   K2 key2)

add

public void add(K1 key1,
                K2 key2,
                V value)
Adds the value to the Collection mapped to by the key.


add

public void add(K1 key1,
                K2 key2,
                java.util.Collection<V> value)
Adds a collection of values to the Collection mapped to by the key.


addKey

public void addKey(K1 key1)
yes, this is a weird method, but i need it.


clear

public void clear()

keySet

public java.util.Set<K1> keySet()
Returns:
a Set view of the keys in this Map.

entrySet

public java.util.Set<java.util.Map.Entry<K1,CollectionValuedMap<K2,V>>> entrySet()

containsKey

public boolean containsKey(K1 key)

retainAll

public void retainAll(java.util.Set<K1> keys)

firstKeySet

public java.util.Set<K1> firstKeySet()

secondKeySet

public java.util.Set<K2> secondKeySet()

values

public java.util.Collection<V> values()


Stanford NLP Group