Package edu.stanford.nlp.util
Class TwoDimensionalCollectionValuedMap<K1,K2,V>
- java.lang.Object
-
- edu.stanford.nlp.util.TwoDimensionalCollectionValuedMap<K1,K2,V>
-
- All Implemented Interfaces:
Serializable
public class TwoDimensionalCollectionValuedMap<K1,K2,V> extends Object implements Serializable
A class which can store mappings from Object keys toCollections of Object values. Important methods are theadd(K1, K2, V)and for adding a value to/from the Collection associated with the key, and theget(K1, K2)method for getting the Collection associated with a key. The class is quite general, because on construction, it is possible to pass aMapFactorywhich will be used to create the underlying map and aCollectionFactorywhich 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
Fields Modifier and Type Field Description protected CollectionFactory<V>cfprotected MapFactory<K2,Collection<V>>mf
-
Constructor Summary
Constructors Constructor Description TwoDimensionalCollectionValuedMap()Creates a new empty TwoDimensionalCollectionValuedMap which uses a HashMap as the underlying Map, and HashSets as the Collections in each mapping.TwoDimensionalCollectionValuedMap(boolean treatCollectionsAsImmutable)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,Collection<V>> mf, CollectionFactory<V> cf)Creates a new empty TwoDimensionalCollectionValuedMap.TwoDimensionalCollectionValuedMap(MapFactory<K2,Collection<V>> mf, CollectionFactory<V> cf, boolean treatCollectionsAsImmutable)Creates a new empty TwoDimensionalCollectionValuedMap.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(K1 key1, K2 key2, Collection<V> value)Adds a collection of values to the Collection mapped to by the key.voidadd(K1 key1, K2 key2, V value)Adds the value to the Collection mapped to by the key.voidaddKey(K1 key1)yes, this is a weird method, but i need it.voidclear()booleancontainsKey(K1 key)Set<Map.Entry<K1,CollectionValuedMap<K2,V>>>entrySet()Set<K1>firstKeySet()Collection<V>get(K1 key1, K2 key2)CollectionValuedMap<K2,V>getCollectionValuedMap(K1 key1)Set<K1>keySet()voidputAll(Map<K1,CollectionValuedMap<K2,V>> toAdd)voidretainAll(Set<K1> keys)Set<K2>secondKeySet()StringtoString()Collection<V>values()
-
-
-
Field Detail
-
mf
protected MapFactory<K2,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(boolean treatCollectionsAsImmutable)
Creates a new empty TwoDimensionalCollectionValuedMap which uses a HashMap as the underlying Map, and HashSets as the Collections in each mapping.- Parameters:
treatCollectionsAsImmutable- whether or not to 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,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 Mapcf- a CollectionFactory which will be used to generate the Collections in each mapping
-
TwoDimensionalCollectionValuedMap
public TwoDimensionalCollectionValuedMap(MapFactory<K2,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 Mapcf- a CollectionFactory which will be used to generate the Collections in each mappingtreatCollectionsAsImmutable- 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
-
putAll
public void putAll(Map<K1,CollectionValuedMap<K2,V>> toAdd)
-
getCollectionValuedMap
public CollectionValuedMap<K2,V> getCollectionValuedMap(K1 key1)
- Returns:
- the Collection mapped to by key, never null, but may be empty.
-
get
public 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, 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()
-
containsKey
public boolean containsKey(K1 key)
-
values
public Collection<V> values()
-
-