Class AbstractCollectionMap<K,V>

java.lang.Object
org.jppf.utils.collections.AbstractCollectionMap<K,V>
Type Parameters:
K - the type of keys in the map.
V - the type of values in the collections mapped to the keys.
All Implemented Interfaces:
Serializable, Iterable<V>, CollectionMap<K,V>
Direct Known Subclasses:
AbstractCollectionConcurrentMap, AbstractCollectionHashtable, AbstractCollectionSortedMap, ArrayListHashMap, EnumSetEnumMap, LinkedListHashMap, SetHashMap, SetIdentityMap

public abstract class AbstractCollectionMap<K,V> extends Object implements CollectionMap<K,V>
A map whose values are collections of a given component type.
Author:
Laurent Cohen
See Also:
  • Field Details

    • map

      protected Map<K,Collection<V>> map
      The underlying map to which operations are delegated.
  • Constructor Details

    • AbstractCollectionMap

      public AbstractCollectionMap()
      Default constructor.
  • Method Details

    • putValue

      public void putValue(K key, V value)
      Description copied from interface: CollectionMap
      Add a value for the specified key.
      Specified by:
      putValue in interface CollectionMap<K,V>
      Parameters:
      key - the key for which to add a value.
      value - the value to add.
    • removeValue

      public boolean removeValue(K key, V value)
      Description copied from interface: CollectionMap
      Remove a value from the specified key.
      Specified by:
      removeValue in interface CollectionMap<K,V>
      Parameters:
      key - the key from which to remove a value.
      value - the value to remove.
      Returns:
      true if an element was removed, false otherwise.
    • addValues

      public void addValues(K key, Collection<V> values)
      Description copied from interface: CollectionMap
      Add the specified values to the specified key. This is a bulk operation.
      Specified by:
      addValues in interface CollectionMap<K,V>
      Parameters:
      key - the key to which to add the values.
      values - the values to add to the key.
    • addValues

      public void addValues(K key, V... values)
      Description copied from interface: CollectionMap
      Add the specified values to the specified key. This is a bulk operation.
      Specified by:
      addValues in interface CollectionMap<K,V>
      Parameters:
      key - the key to which to add the values.
      values - the values to add to the key.
    • removeValues

      public int removeValues(K key, V... values)
      Description copied from interface: CollectionMap
      Remove the specified values from the specified key. This is a bulk operation.
      Specified by:
      removeValues in interface CollectionMap<K,V>
      Parameters:
      key - the key for which to rmeove the values.
      values - the values to remove.
      Returns:
      the number of values that were actually removed, possibly zero.
    • removeKey

      public Collection<V> removeKey(K key)
      Description copied from interface: CollectionMap
      Remove the specified key from this map.
      Specified by:
      removeKey in interface CollectionMap<K,V>
      Parameters:
      key - the key to remove.
      Returns:
      collection of values that were removed, possibly null.
    • getValues

      public Collection<V> getValues(K key)
      Description copied from interface: CollectionMap
      Get the collection of values maped to the specified key.
      Specified by:
      getValues in interface CollectionMap<K,V>
      Parameters:
      key - the key to lookup.
      Returns:
      a collection of values that mapped to the key, or null if no mapping exists for the key.
    • size

      public int size()
      Description copied from interface: CollectionMap
      Get the total number of elements in this collection map. Note that the cost of the size() operation will be in O(n).
      Specified by:
      size in interface CollectionMap<K,V>
      Returns:
      the number of elements as an int value.
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: CollectionMap
      Determine whether this map is empty.
      Specified by:
      isEmpty in interface CollectionMap<K,V>
      Returns:
      true if the map is empty, false otherwise.
    • containsKey

      public boolean containsKey(K key)
      Description copied from interface: CollectionMap
      Determine whether this map contains the specified key.
      Specified by:
      containsKey in interface CollectionMap<K,V>
      Parameters:
      key - the key to lookup.
      Returns:
      true if there is a mapping for the key, false otherwise.
    • containsValue

      public boolean containsValue(K key, V value)
      Description copied from interface: CollectionMap
      Determine whether the collection mapped to the specified key contains the specified value.
      Specified by:
      containsValue in interface CollectionMap<K,V>
      Parameters:
      key - the key whose mapped collection is looked up^.
      value - the value to look in the collection.
      Returns:
      true if the map contains the key and the corresponding collection contains the value, false otehrwise.
    • containsValue

      public boolean containsValue(V value)
      Description copied from interface: CollectionMap
      Determine whether at least one of the collections in the map contains the specified value.
      Specified by:
      containsValue in interface CollectionMap<K,V>
      Parameters:
      value - the value to look up in the entire map.
      Returns:
      true if the map contains the value, false otehrwise.
    • iterator

      public Iterator<V> iterator()
      Specified by:
      iterator in interface Iterable<K>
    • iterator

      public Iterator<V> iterator(Lock lock)
      Description copied from interface: CollectionMap
      Get an iterator which uses the specified lock.
      Specified by:
      iterator in interface CollectionMap<K,V>
      Parameters:
      lock - the lock used to synchronize access to the map.
      Returns:
      an iterator on the values of the map.
    • clear

      public void clear()
      Description copied from interface: CollectionMap
      Clear the map.
      Specified by:
      clear in interface CollectionMap<K,V>
    • createMap

      protected abstract Map<K,Collection<V>> createMap()
      Create a new map.
      Returns:
      a new mutable empty map.
    • newCollection

      protected abstract Collection<V> newCollection()
      Create a new collection of values for insertion into the map.
      Returns:
      a new mutable empty collection.
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • keySet

      public Set<K> keySet()
      Description copied from interface: CollectionMap
      Get the set of keys in the map.
      Specified by:
      keySet in interface CollectionMap<K,V>
      Returns:
      a Set of all keys.
    • entrySet

      public Set<Map.Entry<K,Collection<V>>> entrySet()
      Description copied from interface: CollectionMap
      Get the set map entries.
      Specified by:
      entrySet in interface CollectionMap<K,V>
      Returns:
      a Set of all map entries.
    • allValues

      public List<V> allValues()
      Description copied from interface: CollectionMap
      Get a collection of all the values for all keys.
      Specified by:
      allValues in interface CollectionMap<K,V>
      Returns:
      a collection of all values in this map.
    • createOrGetCollectionSynchronized

      protected Collection<V> createOrGetCollectionSynchronized(K key)
      Get an exisitng collection for the specified key, or create it if it doesn't exist.
      Parameters:
      key - the key for which to get a collection of values.
      Returns:
      a collection of value for the specified keys, may be empty if newly created.
    • createOrGetCollection

      protected Collection<V> createOrGetCollection(K key)
      Get an exisitng collection for the specified key, or create it if it doesn't exist.
      Parameters:
      key - the key for which to get a collection of values.
      Returns:
      a collection of value for the specified keys, may be empty if newly created.