K
- Key type of mapV
- Type of the Collection that is the Map's valuepublic class CollectionValuedMap<K,V> extends Object implements Map<K,Collection<V>>, Serializable
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!Modifier and Type | Field and Description |
---|---|
protected CollectionFactory<V> |
cf |
protected MapFactory<K,Collection<V>> |
mf |
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
void |
add(K key,
V value)
Adds the value to the Collection mapped to by the key.
|
void |
addAll(CollectionValuedMap<K,V> cvm) |
void |
addAll(K key,
Collection<V> values)
Adds the values to the Collection mapped to by the key.
|
void |
addAll(Map<K,V> m)
Adds all of the mappings in m to this CollectionValuedMap.
|
void |
addKey(K key) |
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 |
removeAll(Collection<K> keys)
removes the mappings associated with the keys 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() |
finalize, getClass, notify, notifyAll, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, forEach, getOrDefault, merge, putIfAbsent, remove, replace, replace, replaceAll
protected CollectionFactory<V> cf
protected MapFactory<K,Collection<V>> mf
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 mappingpublic 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 addAll(K key, Collection<V> values)
public void addKey(K key)
public void addAll(Map<K,V> m)
public void addAll(CollectionValuedMap<K,V> cvm)
public Collection<V> remove(Object key)
remove
in interface Map<K,Collection<V>>
public void removeAll(Collection<K> keys)
keys
- 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)
public int hashCode()
public CollectionValuedMap<K,V> deltaClone()
public CollectionValuedMap<K,V> clone()
public String toString()
public static void main(String[] args)
args
- from command line