Class SynchronizedMultiMap<K,V>
java.lang.Object
net.okapia.osid.torrefacto.collect.SynchronizedMultiMap<K,V>
- Type Parameters:
K- the key typeV- the value type
- All Implemented Interfaces:
MultiMap<K,V>
A thread-safe view of a
MultiMap. Every operation delegates
to the backing map inside a block synchronized on that map, so
individual calls are serialized.
Like Collections.synchronizedMap(Map), the collection
views returned by keySet(), values(), and asMap() are not themselves synchronized and must not be
iterated while the map is being modified from another thread.
Compound operations (for example, check-then-act) are likewise not
atomic. Obtain an instance through Collections.synchronizedMultiMap(MultiMap).-
Constructor Summary
ConstructorsConstructorDescriptionSynchronizedMultiMap(MultiMap<K, V> map) Constructs a new SynchronizedMultiMap wrapping the given map. -
Method Summary
Modifier and TypeMethodDescriptionMap<K, Collection<V>> asMap()Gets a Map of this MultiMap.voidclear()Removes all of the mappings from this map.booleancontainsKey(K key) Tests if this map contains a mapping for the specified key.booleancontainsKeyValue(K key, V value) Tests the map contains the key and value specified.booleancontainsValue(V value) Tests the map contains the value specified.Gets the values to which the specified key is mapped.booleanisEmpty()Tests if this map contains no key-value mappings.booleanTests if this map can be modified.keySet()Returns an immutable Collection view of the keys contained in this map.voidAssociates the specified value with the specified key in this map.voidputAll(Map<K, Collection<? extends V>> map) Stores a map of keys and values inside this map.voidputAll(K key, Collection<? extends V> values) Adds a collection of values to to a key in this mapvoidStores a Multimap inside this map.voidRemoves the mapping for a key and all its related values.voidRemoves a specific key/value pair from the map.voidremoveValue(V value) Removes a value.longsize()Returns the number of key-value mappings in this map.values()Returns a Collection view of the values contained in this map.
-
Constructor Details
-
SynchronizedMultiMap
Constructs a new SynchronizedMultiMap wrapping the given map.- Parameters:
map- the multimap to synchronize- Throws:
NullArgumentException-mapisnull
-
-
Method Details
-
isModifiable
public boolean isModifiable()Tests if this map can be modified.- Specified by:
isModifiablein interfaceMultiMap<K,V> - Returns:
trueif the map can be modified,falseif read-only
-
size
-
isEmpty
-
containsKey
Tests if this map contains a mapping for the specified key.- Specified by:
containsKeyin interfaceMultiMap<K,V> - Parameters:
key- the key whose presence in this map is to be tested- Returns:
trueif this map contains a mapping for the specified key,falseotherwise- Throws:
NullArgumentException-keyisnull
-
containsValue
Tests the map contains the value specified.- Specified by:
containsValuein interfaceMultiMap<K,V> - Parameters:
value- the value to search for- Returns:
trueif the map contains the value,falseotherwise- Throws:
NullArgumentException-valueisnull
-
containsKeyValue
Tests the map contains the key and value specified.- Specified by:
containsKeyValuein interfaceMultiMap<K,V> - Parameters:
key- the keyvalue- the value- Returns:
trueif the map contains the key/value pair,falseotherwise- Throws:
NullArgumentException-keyorvalueisnull
-
get
Gets the values to which the specified key is mapped. If the key is not defined, this method returns an empty list.- Specified by:
getin interfaceMultiMap<K,V> - Parameters:
key- the key- Returns:
- a collection of the values for the given key or an empty collection if the key is not found
- Throws:
NullArgumentException-keyisnull
-
put
Associates the specified value with the specified key in this map. If the map previously contained a mapping for the key, the old value is replaced.- Specified by:
putin interfaceMultiMap<K,V> - Parameters:
key- key with which the specified value is to be associatedvalue- value to be associated with the specified key- Throws:
NullArgumentException-keyorvalueisnullUnsupportedException- map is not modifiable
-
putAll
Adds a collection of values to to a key in this map- Specified by:
putAllin interfaceMultiMap<K,V> - Parameters:
key- the keyvalues- the values- Throws:
NullArgumentException-keyorvaluesisnullUnsupportedException- map is not modifiable
-
putAll
Stores a map of keys and values inside this map.- Specified by:
putAllin interfaceMultiMap<K,V> - Parameters:
map- the map to store- Throws:
NullArgumentException-mapisnullUnsupportedException- map is not modifiable
-
putAll
Stores a Multimap inside this map.- Specified by:
putAllin interfaceMultiMap<K,V> - Parameters:
map- the map to store- Throws:
NullArgumentException-mapisnullUnsupportedException- map is not modifiable
-
remove
Removes the mapping for a key and all its related values.- Specified by:
removein interfaceMultiMap<K,V> - Parameters:
key- whose mapping is to be removed from the map- Throws:
NullArgumentException-keyisnullUnsupportedException- map is not modifiable
-
removeValue
Removes a value.- Specified by:
removeValuein interfaceMultiMap<K,V> - Parameters:
value- to be removed from the map- Throws:
NullArgumentException-valueisnull
-
remove
Removes a specific key/value pair from the map. The item is removed from the collection mapped to the specified key. Other values attached to that key are unaffected.- Specified by:
removein interfaceMultiMap<K,V> - Parameters:
key- the keyvalue- the value to remove- Throws:
NullArgumentException-keyorvalueisnullUnsupportedException- map is not modifiable
-
clear
public void clear()Removes all of the mappings from this map. The map will be empty after this call returns.- Specified by:
clearin interfaceMultiMap<K,V> - Throws:
UnsupportedException- map is not modifiable
-
keySet
-
values
-
asMap
-