MultiValuedMap instead
@Deprecated public class MultiValueMap<K,V> extends AbstractMapDecorator<K ,Object > implements MultiMap <K ,V>, 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.
| Modifier | Constructor and Description |
|---|---|
|
MultiValueMap()
Deprecated.
Creates a MultiValueMap based on a
HashMap and storing the multiple values in an
ArrayList.
|
protected |
MultiValueMap(Map
Deprecated.
Creates a MultiValueMap which decorates the given
map and creates the value collections using the supplied
collectionFactory.
|
| Modifier and Type | Method and Description |
|---|---|
void |
clear()
Deprecated.
Clear the map.
|
boolean |
containsValue(Object
Deprecated.
Checks whether the map contains the value specified.
|
boolean |
containsValue(Object
Deprecated.
Checks whether the collection at the specified key contains the value.
|
protected Collection |
createCollection(int size)
Deprecated.
Creates a new instance of the map value Collection container using the factory.
|
Set |
entrySet()
Deprecated.
|
Collection |
getCollection(Object
Deprecated.
Gets the collection mapped to the specified key.
|
Iterator |
iterator()
Deprecated.
Gets an iterator for all mappings stored in this
MultiValueMap.
|
Iterator |
iterator(Object
Deprecated.
Gets an iterator for the collection mapped to the specified key.
|
static <K |
multiValueMap(Map
Deprecated.
Creates a map which decorates the given
map and maps keys to collections of type
collectionClass.
|
static <K |
multiValueMap(Map
Deprecated.
Creates a map which decorates the given
map and creates the value collections using the supplied
collectionFactory.
|
static <K |
multiValueMap(Map
Deprecated.
Creates a map which wraps the given map and maps keys to ArrayLists.
|
Object |
put(K key, Object
Deprecated.
Adds the value to the collection associated with the specified key.
|
boolean |
putAll(K key, Collection
Deprecated.
Adds a collection of values to the collection associated with the specified key.
|
void |
putAll(Map
Deprecated.
Override superclass to ensure that MultiMap instances are correctly handled.
|
boolean |
removeMapping(Object
Deprecated.
Removes a specific value from map.
|
int |
size(Object
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.
|
Collection |
values()
Deprecated.
Gets a collection containing all the values in the map.
|
containsKey, decorated, equals, get, hashCode, isEmpty, keySet, remove, size, toStringmapIteratorclone, finalize, getClass, notify, notifyAll, wait, wait, waitcompute, computeIfAbsent, computeIfPresent, containsKey, equals, forEach, getOrDefault, hashCode, isEmpty, keySet, merge, putIfAbsent, remove, replace, replace, replaceAllmapIteratorcontainsKey, isEmpty, keySetpublic MultiValueMap()
HashMap and storing the multiple values in an
ArrayList.
protected MultiValueMap(Map<K ,? super C> map, Factory <C> collectionFactory)
map and creates the value collections using the supplied
collectionFactory.
C - the collection class type
map - the map to decorate
collectionFactory - the collection factory which must return a Collection instance
public static <K,V> MultiValueMap <K ,V> multiValueMap(Map <K ,? super Collection <V>> map)
K - the key type
V - the value type
map - the map to wrap
public static <K,V ,C extends Collection <V>> MultiValueMap <K ,V> multiValueMap(Map <K ,? super C> map, Class <C> collectionClass)
map and maps keys to collections of type
collectionClass.
K - the key type
V - the value type
C - the collection class type
map - the map to wrap
collectionClass - the type of the collection class
public static <K,V ,C extends Collection <V>> MultiValueMap <K ,V> multiValueMap(Map <K ,? super C> map, Factory <C> collectionFactory)
map and creates the value collections using the supplied
collectionFactory.
K - the key type
V - the value type
C - the collection class type
map - the map to decorate
collectionFactory - the collection factory (must return a Collection object).
public void clear()
public boolean removeMapping(Objectkey, 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 from
value - the value to remove
true if the mapping was removed,
false otherwise
public boolean containsValue(Objectvalue)
This checks all collections against all keys for the value, and thus could be slow.
containsValue in interface
Map<K,Object>
containsValue in interface
Get<K,Object>
containsValue in interface
MultiMap<K,V>
containsValue in class
AbstractMapDecorator<K,Object>
value - the value to search for
Map.containsValue(Object)
public Objectput(K key, 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
Map<K,Object>
put in interface
MultiMap<K,V>
put in interface
Put<K,Object>
put in class
AbstractMapDecorator<K,Object>
key - the key to store against
value - the value to add to the collection at the key
Map.put(Object, Object)
public void putAll(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 Set<Map .Entry <K ,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().
public Collection<Object > values()
This returns a collection containing the combination of values from all keys.
public boolean containsValue(Objectkey, Object value)
key - the key to search for
value - the value to search for
public Collection<V> getCollection(Object key)
get(key).
key - the key to retrieve
public int size(Objectkey)
key - the key to get size for
public boolean putAll(K key, Collection<V> values)
key - the key to store against
values - the values to add to the collection at the key, null ignored
public Iterator<V> iterator(Object key)
key - the key to get an iterator for
public Iterator<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 on any of the returned elements will result in a UnsupportedOperationException.
public int totalSize()
protected Collection<V> createCollection(int size)
This method can be overridden to perform your own processing instead of using the factory.
size - the collection size that is about to be added