|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectedu.stanford.nlp.util.CollectionValuedMap<K,V>
K
- Key type of mapV
- Type of the Collection that is the Map's valuepublic class CollectionValuedMap<K,V>
Map from keys to Collection
s.
Important methods are the add(K, V)
and remove(java.lang.Object)
methods for adding and removing a value
to/from the Collection associated with the key, and the get(java.lang.Object)
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!
Nested Class Summary |
---|
Nested classes/interfaces inherited from interface java.util.Map |
---|
Map.Entry<K,V> |
Field Summary | |
---|---|
protected CollectionFactory<V> |
cf
|
protected MapFactory<K,Collection<V>> |
mf
|
Constructor Summary | |
---|---|
CollectionValuedMap()
Creates a new empty CollectionValuedMap which uses a HashMap as the underlying Map, and HashSets as the Collections in each mapping. |
|
CollectionValuedMap(CollectionFactory<V> cf)
Creates a new empty CollectionValuedMap which uses a HashMap as the underlying Map. |
|
CollectionValuedMap(CollectionValuedMap<K,V> cvm)
Creates a new CollectionValuedMap with all of the mappings from cvm. |
|
CollectionValuedMap(MapFactory<K,Collection<V>> mf,
CollectionFactory<V> cf,
boolean treatCollectionsAsImmutable)
Creates a new empty CollectionValuedMap. |
Method Summary | |
---|---|
void |
add(K key,
V value)
Adds the value to the Collection mapped to by the key. |
void |
addAll(Map<K,V> m)
Adds all of the mappings in m to this CollectionValuedMap. |
Collection<V> |
allValues()
|
void |
clear()
Clears this Map. |
CollectionValuedMap<K,V> |
clone()
|
boolean |
containsKey(Object key)
|
boolean |
containsValue(Object value)
Unsupported. |
CollectionValuedMap<K,V> |
deltaClone()
Creates a "delta clone" of this Map, where only the differences are represented. |
Set<Map.Entry<K,Collection<V>>> |
entrySet()
Each element of the Set is a Map.Entry object, where getKey() returns the key of the mapping, and getValue() returns the Collection mapped to by the key. |
boolean |
equals(Object o)
|
Collection<V> |
get(Object key)
|
int |
hashCode()
|
boolean |
isEmpty()
|
Set<K> |
keySet()
|
static void |
main(String[] args)
For testing only. |
Collection<V> |
put(K key,
Collection<V> collection)
Replaces current Collection mapped to key with the specified Collection. |
void |
putAll(Map<? extends K,? extends Collection<V>> m)
Unsupported. |
Collection<V> |
remove(Object key)
Removes the mapping associated with this key from this Map. |
void |
removeMapping(K key,
V value)
Removes the value from the Collection mapped to by this key, leaving the rest of the collection intact. |
int |
size()
The number of keys in this map. |
String |
toString()
|
Collection<Collection<V>> |
values()
Unsupported. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected CollectionFactory<V> cf
protected MapFactory<K,Collection<V>> mf
Constructor Detail |
---|
public CollectionValuedMap(MapFactory<K,Collection<V>> mf, CollectionFactory<V> cf, boolean treatCollectionsAsImmutable)
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.public CollectionValuedMap(CollectionValuedMap<K,V> cvm)
clone()
.
public CollectionValuedMap()
public CollectionValuedMap(CollectionFactory<V> cf)
cf
- a CollectionFactory which will be used to generate the
Collections in each mappingMethod Detail |
---|
public Collection<V> put(K key, Collection<V> collection)
put
in interface Map<K,Collection<V>>
public void putAll(Map<? extends K,? extends Collection<V>> m)
addAll(Map)
instead.
putAll
in interface Map<K,Collection<V>>
public Collection<V> get(Object key)
get
in interface Map<K,Collection<V>>
public void add(K key, V value)
public void addAll(Map<K,V> m)
public Collection<V> remove(Object key)
remove
in interface Map<K,Collection<V>>
public void removeMapping(K key, V value)
key
- the key to the Collection to remove the value fromvalue
- the value to removepublic void clear()
clear
in interface Map<K,Collection<V>>
public boolean containsKey(Object key)
containsKey
in interface Map<K,Collection<V>>
public boolean containsValue(Object value)
containsValue
in interface Map<K,Collection<V>>
public boolean isEmpty()
isEmpty
in interface Map<K,Collection<V>>
public Set<Map.Entry<K,Collection<V>>> entrySet()
entrySet
in interface Map<K,Collection<V>>
public Set<K> keySet()
keySet
in interface Map<K,Collection<V>>
public int size()
size
in interface Map<K,Collection<V>>
public Collection<Collection<V>> values()
values
in interface Map<K,Collection<V>>
public Collection<V> allValues()
public boolean equals(Object o)
equals
in interface Map<K,Collection<V>>
equals
in class Object
public int hashCode()
hashCode
in interface Map<K,Collection<V>>
hashCode
in class Object
public CollectionValuedMap<K,V> deltaClone()
public CollectionValuedMap<K,V> clone()
clone
in class Object
public String toString()
toString
in class Object
public static void main(String[] args)
args
- from command line
|
|||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |