K
- the type of the keys in this mapV
- the type of the values in this mapMultiValuedMap
instead@Deprecated public class MultiValueMap<K,V> extends AbstractMapDecorator<K,java.lang.Object> implements MultiMap<K,V>, java.io.Serializable
A MultiMap
is a Map with slightly different semantics.
Putting a value into the map will add the value to a Collection at that key.
Getting a value will return a Collection, holding all the values put to that key.
This implementation is a decorator, allowing any Map implementation to be used as the base.
In addition, this implementation allows the type of collection used
for the values to be controlled. By default, an ArrayList
is used, however a Class
to instantiate may be specified,
or a factory that returns a Collection
instance.
Note that MultiValueMap is not synchronized and is not thread-safe. If you wish to use this map from multiple threads concurrently, you must use appropriate synchronization. This class may throw exceptions when accessed by concurrent threads without synchronization.
Constructor and Description |
---|
MultiValueMap()
Deprecated.
Creates a MultiValueMap based on a
HashMap and
storing the multiple values in an ArrayList . |
Modifier and Type | Method and Description |
---|---|
void |
clear()
Deprecated.
Clear the map.
|
boolean |
containsValue(java.lang.Object value)
Deprecated.
Checks whether the map contains the value specified.
|
boolean |
containsValue(java.lang.Object key,
java.lang.Object value)
Deprecated.
Checks whether the collection at the specified key contains the value.
|
java.util.Set<java.util.Map.Entry<K,java.lang.Object>> |
entrySet()
Deprecated.
|
java.util.Collection<V> |
getCollection(java.lang.Object key)
Deprecated.
Gets the collection mapped to the specified key.
|
java.util.Iterator<java.util.Map.Entry<K,V>> |
iterator()
Deprecated.
Gets an iterator for all mappings stored in this
MultiValueMap . |
java.util.Iterator<V> |
iterator(java.lang.Object key)
Deprecated.
Gets an iterator for the collection mapped to the specified key.
|
static <K,V,C extends java.util.Collection<V>> |
multiValueMap(java.util.Map<K,? super C> map,
java.lang.Class<C> collectionClass)
Deprecated.
Creates a map which decorates the given
map and
maps keys to collections of type collectionClass . |
static <K,V,C extends java.util.Collection<V>> |
multiValueMap(java.util.Map<K,? super C> map,
Factory<C> collectionFactory)
Deprecated.
Creates a map which decorates the given
map and
creates the value collections using the supplied collectionFactory . |
static <K,V> MultiValueMap<K,V> |
multiValueMap(java.util.Map<K,? super java.util.Collection<V>> map)
Deprecated.
Creates a map which wraps the given map and
maps keys to ArrayLists.
|
java.lang.Object |
put(K key,
java.lang.Object value)
Deprecated.
Adds the value to the collection associated with the specified key.
|
boolean |
putAll(K key,
java.util.Collection<V> values)
Deprecated.
Adds a collection of values to the collection associated with
the specified key.
|
void |
putAll(java.util.Map<? extends K,?> map)
Deprecated.
Override superclass to ensure that MultiMap instances are
correctly handled.
|
boolean |
removeMapping(java.lang.Object key,
java.lang.Object value)
Deprecated.
Removes a specific value from map.
|
int |
size(java.lang.Object key)
Deprecated.
Gets the size of the collection mapped to the specified key.
|
int |
totalSize()
Deprecated.
Gets the total size of the map by counting all the values.
|
java.util.Collection<java.lang.Object> |
values()
Deprecated.
Gets a collection containing all the values in the map.
|
containsKey, equals, get, hashCode, isEmpty, keySet, remove, size, toString
mapIterator
compute, computeIfAbsent, computeIfPresent, containsKey, equals, forEach, getOrDefault, hashCode, isEmpty, keySet, merge, putIfAbsent, remove, replace, replace, replaceAll
mapIterator
containsKey, isEmpty, keySet
public MultiValueMap()
HashMap
and
storing the multiple values in an ArrayList
.public static <K,V> MultiValueMap<K,V> multiValueMap(java.util.Map<K,? super java.util.Collection<V>> map)
K
- the key typeV
- the value typemap
- the map to wrappublic static <K,V,C extends java.util.Collection<V>> MultiValueMap<K,V> multiValueMap(java.util.Map<K,? super C> map, java.lang.Class<C> collectionClass)
map
and
maps keys to collections of type collectionClass
.K
- the key typeV
- the value typeC
- the collection class typemap
- the map to wrapcollectionClass
- the type of the collection classpublic static <K,V,C extends java.util.Collection<V>> MultiValueMap<K,V> multiValueMap(java.util.Map<K,? super C> map, Factory<C> collectionFactory)
map
and
creates the value collections using the supplied collectionFactory
.K
- the key typeV
- the value typeC
- the collection class typemap
- the map to decoratecollectionFactory
- the collection factory (must return a Collection object).public void clear()
public boolean removeMapping(java.lang.Object key, java.lang.Object value)
The item is removed from the collection mapped to the specified key. Other values attached to that key are unaffected.
If the last value for a key is removed, null
will be returned
from a subsequent get(key)
.
removeMapping
in interface MultiMap<K,V>
key
- the key to remove fromvalue
- the value to removetrue
if the mapping was removed, false
otherwisepublic boolean containsValue(java.lang.Object value)
This checks all collections against all keys for the value, and thus could be slow.
containsValue
in interface java.util.Map<K,java.lang.Object>
containsValue
in interface Get<K,java.lang.Object>
containsValue
in interface MultiMap<K,V>
containsValue
in class AbstractMapDecorator<K,java.lang.Object>
value
- the value to search forMap.containsValue(Object)
public java.lang.Object put(K key, java.lang.Object value)
Unlike a normal Map
the previous value is not replaced.
Instead the new value is added to the collection stored against the key.
put
in interface java.util.Map<K,java.lang.Object>
put
in interface MultiMap<K,V>
put
in interface Put<K,java.lang.Object>
put
in class AbstractMapDecorator<K,java.lang.Object>
key
- the key to store againstvalue
- the value to add to the collection at the keyMap.put(Object, Object)
public void putAll(java.util.Map<? extends K,?> map)
If you call this method with a normal map, each entry is
added using put(Object,Object)
.
If you call this method with a multi map, each entry is
added using putAll(Object,Collection)
.
public java.util.Set<java.util.Map.Entry<K,java.lang.Object>> entrySet()
NOTE: the returned Entry objects will contain as value a Collection
of all values that are mapped to the given key. To get a "flattened" version
of all mappings contained in this map, use iterator()
.
entrySet
in interface java.util.Map<K,java.lang.Object>
entrySet
in interface Get<K,java.lang.Object>
entrySet
in class AbstractMapDecorator<K,java.lang.Object>
iterator()
public java.util.Collection<java.lang.Object> values()
This returns a collection containing the combination of values from all keys.
values
in interface java.util.Map<K,java.lang.Object>
values
in interface Get<K,java.lang.Object>
values
in interface MultiMap<K,V>
values
in class AbstractMapDecorator<K,java.lang.Object>
Map.values()
public boolean containsValue(java.lang.Object key, java.lang.Object value)
key
- the key to search forvalue
- the value to search forpublic java.util.Collection<V> getCollection(java.lang.Object key)
get(key)
.key
- the key to retrievepublic int size(java.lang.Object key)
key
- the key to get size forpublic boolean putAll(K key, java.util.Collection<V> values)
key
- the key to store againstvalues
- the values to add to the collection at the key, null ignoredpublic java.util.Iterator<V> iterator(java.lang.Object key)
key
- the key to get an iterator forpublic java.util.Iterator<java.util.Map.Entry<K,V>> iterator()
MultiValueMap
.
The iterator will return multiple Entry objects with the same key if there are multiple values mapped to this key.
NOTE: calling Map.Entry.setValue(Object)
on any of the returned
elements will result in a UnsupportedOperationException
.
public int totalSize()
Copyright © 2010 - 2020 Adobe. All Rights Reserved