Class SynchronizedMultiMap<K,V>

java.lang.Object
net.okapia.osid.torrefacto.collect.SynchronizedMultiMap<K,V>
Type Parameters:
K - the key type
V - the value type
All Implemented Interfaces:
MultiMap<K,V>

public class SynchronizedMultiMap<K,V> extends Object implements 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

    Constructors
    Constructor
    Description
    Constructs a new SynchronizedMultiMap wrapping the given map.
  • Method Summary

    Modifier and Type
    Method
    Description
    Gets a Map of this MultiMap.
    void
    Removes all of the mappings from this map.
    boolean
    Tests if this map contains a mapping for the specified key.
    boolean
    containsKeyValue(K key, V value)
    Tests the map contains the key and value specified.
    boolean
    Tests the map contains the value specified.
    get(K key)
    Gets the values to which the specified key is mapped.
    boolean
    Tests if this map contains no key-value mappings.
    boolean
    Tests if this map can be modified.
    Returns an immutable Collection view of the keys contained in this map.
    void
    put(K key, V value)
    Associates the specified value with the specified key in this map.
    void
    putAll(Map<K, Collection<? extends V>> map)
    Stores a map of keys and values inside this map.
    void
    putAll(K key, Collection<? extends V> values)
    Adds a collection of values to to a key in this map
    void
    putAll(MultiMap<K, ? extends V> map)
    Stores a Multimap inside this map.
    void
    remove(K key)
    Removes the mapping for a key and all its related values.
    void
    remove(K key, V value)
    Removes a specific key/value pair from the map.
    void
    removeValue(V value)
    Removes a value.
    long
    Returns the number of key-value mappings in this map.
    Returns a Collection view of the values contained in this map.

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • SynchronizedMultiMap

      public SynchronizedMultiMap(MultiMap<K,V> map)
      Constructs a new SynchronizedMultiMap wrapping the given map.
      Parameters:
      map - the multimap to synchronize
      Throws:
      NullArgumentException - map is null
  • Method Details

    • isModifiable

      public boolean isModifiable()
      Tests if this map can be modified.
      Specified by:
      isModifiable in interface MultiMap<K,V>
      Returns:
      true if the map can be modified, false if read-only
    • size

      public long size()
      Returns the number of key-value mappings in this map.
      Specified by:
      size in interface MultiMap<K,V>
      Returns:
      the number of key-value mappings in this map
    • isEmpty

      public boolean isEmpty()
      Tests if this map contains no key-value mappings.
      Specified by:
      isEmpty in interface MultiMap<K,V>
      Returns:
      true if this map contains no key-value mappings, false otherwise
    • containsKey

      public boolean containsKey(K key)
      Tests if this map contains a mapping for the specified key.
      Specified by:
      containsKey in interface MultiMap<K,V>
      Parameters:
      key - the key whose presence in this map is to be tested
      Returns:
      true if this map contains a mapping for the specified key, false otherwise
      Throws:
      NullArgumentException - key is null
    • containsValue

      public boolean containsValue(V value)
      Tests the map contains the value specified.
      Specified by:
      containsValue in interface MultiMap<K,V>
      Parameters:
      value - the value to search for
      Returns:
      true if the map contains the value, false otherwise
      Throws:
      NullArgumentException - value is null
    • containsKeyValue

      public boolean containsKeyValue(K key, V value)
      Tests the map contains the key and value specified.
      Specified by:
      containsKeyValue in interface MultiMap<K,V>
      Parameters:
      key - the key
      value - the value
      Returns:
      true if the map contains the key/value pair, false otherwise
      Throws:
      NullArgumentException - key or value is null
    • get

      public Collection<V> get(K key)
      Gets the values to which the specified key is mapped. If the key is not defined, this method returns an empty list.
      Specified by:
      get in interface MultiMap<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 - key is null
    • put

      public void put(K key, V value)
      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:
      put in interface MultiMap<K,V>
      Parameters:
      key - key with which the specified value is to be associated
      value - value to be associated with the specified key
      Throws:
      NullArgumentException - key or value is null
      UnsupportedException - map is not modifiable
    • putAll

      public void putAll(K key, Collection<? extends V> values)
      Adds a collection of values to to a key in this map
      Specified by:
      putAll in interface MultiMap<K,V>
      Parameters:
      key - the key
      values - the values
      Throws:
      NullArgumentException - key or values is null
      UnsupportedException - map is not modifiable
    • putAll

      public void putAll(Map<K, Collection<? extends V>> map)
      Stores a map of keys and values inside this map.
      Specified by:
      putAll in interface MultiMap<K,V>
      Parameters:
      map - the map to store
      Throws:
      NullArgumentException - map is null
      UnsupportedException - map is not modifiable
    • putAll

      public void putAll(MultiMap<K, ? extends V> map)
      Stores a Multimap inside this map.
      Specified by:
      putAll in interface MultiMap<K,V>
      Parameters:
      map - the map to store
      Throws:
      NullArgumentException - map is null
      UnsupportedException - map is not modifiable
    • remove

      public void remove(K key)
      Removes the mapping for a key and all its related values.
      Specified by:
      remove in interface MultiMap<K,V>
      Parameters:
      key - whose mapping is to be removed from the map
      Throws:
      NullArgumentException - key is null
      UnsupportedException - map is not modifiable
    • removeValue

      public void removeValue(V value)
      Removes a value.
      Specified by:
      removeValue in interface MultiMap<K,V>
      Parameters:
      value - to be removed from the map
      Throws:
      NullArgumentException - value is null
    • remove

      public void remove(K key, V value)
      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:
      remove in interface MultiMap<K,V>
      Parameters:
      key - the key
      value - the value to remove
      Throws:
      NullArgumentException - key or value is null
      UnsupportedException - 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:
      clear in interface MultiMap<K,V>
      Throws:
      UnsupportedException - map is not modifiable
    • keySet

      public Collection<K> keySet()
      Returns an immutable Collection view of the keys contained in this map.
      Specified by:
      keySet in interface MultiMap<K,V>
      Returns:
      a set view of the keys contained in this map
    • values

      public Collection<V> values()
      Returns a Collection view of the values contained in this map.
      Specified by:
      values in interface MultiMap<K,V>
      Returns:
      a collection of the values
    • asMap

      public Map<K, Collection<V>> asMap()
      Gets a Map of this MultiMap.
      Specified by:
      asMap in interface MultiMap<K,V>
      Returns:
      a map view of this MultiMap