|
|||||||||
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>
public class CollectionValuedMap<K,V>
A class which can store mappings from Object keys to Collection
s of Object values.
Important methods are the add(Object key, Object value)
and
removeMapping(Object key, Object value)
methods for adding and removing a value
to/from the Collection associated with the key, and the get(Object key)
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 |
cf
|
protected MapFactory |
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 cf)
Creates a new empty CollectionValuedMap which uses a HashMap as the underlying Map. |
|
CollectionValuedMap(CollectionValuedMap cvm)
Creates a new CollectionValuedMap with all of the mappings from cvm. |
|
CollectionValuedMap(MapFactory mf,
CollectionFactory 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. |
Object |
clone()
|
boolean |
containsKey(Object key)
|
boolean |
containsValue(Object value)
Unsupported. |
Object |
deltaClone()
Creates a "delta clone" of this Map, where only the differences are represented. |
Set |
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 |
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 |
values()
Unsupported. |
Methods inherited from class java.lang.Object |
---|
finalize, getClass, notify, notifyAll, wait, wait, wait |
Field Detail |
---|
protected CollectionFactory cf
protected MapFactory mf
Constructor Detail |
---|
public CollectionValuedMap(MapFactory mf, CollectionFactory 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 cvm)
clone()
.
cvm
- public CollectionValuedMap()
public CollectionValuedMap(CollectionFactory 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>>
key
- collection
-
public void putAll(Map<? extends K,? extends Collection<V>> m)
addAll(Map)
instead.
putAll
in interface Map<K,Collection<V>>
m
- public Collection<V> get(Object key)
get
in interface Map<K,Collection<V>>
key
-
public void add(K key, V value)
key
- value
- public void addAll(Map<K,V> m)
m
- public Collection remove(Object key)
remove
in interface Map<K,Collection<V>>
key
-
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>>
key
-
public boolean containsValue(Object value)
containsValue
in interface Map<K,Collection<V>>
value
-
public boolean isEmpty()
isEmpty
in interface Map<K,Collection<V>>
public Set 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 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
o
-
public int hashCode()
hashCode
in interface Map<K,Collection<V>>
hashCode
in class Object
public Object deltaClone()
public Object 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 |