Class AbstractSetValuedMap<K,V>

java.lang.Object
org.apache.commons.collections4.multimap.AbstractMultiValuedMap<K,V>
org.apache.commons.collections4.multimap.AbstractSetValuedMap<K,V>
All Implemented Interfaces:
MultiValuedMap<K,V>, SetValuedMap<K,V>
Direct Known Subclasses:
HashSetValuedHashMap

public abstract class AbstractSetValuedMap<K,V> extends AbstractMultiValuedMap<K,V> implements SetValuedMap<K,V>
Abstract implementation of the SetValuedMap interface to simplify the creation of subclass implementations.

Subclasses specify a Map implementation to use as the internal storage and the Set implementation to use as values.

Since:
4.1
Version:
$Id: AbstractSetValuedMap.java 1715695 2015-11-22 21:11:49Z tn $
  • Constructor Details

    • AbstractSetValuedMap

      protected AbstractSetValuedMap()
      Constructor needed for subclass serialisation.
    • AbstractSetValuedMap

      protected AbstractSetValuedMap(Map<K,? extends Set<V>> map)
      A constructor that wraps, not copies
      Parameters:
      map - the map to wrap, must not be null
      Throws:
      NullPointerException - if the map is null
  • Method Details

    • getMap

      protected Map<K,Set<V>> getMap()
      Description copied from class: AbstractMultiValuedMap
      Gets the map being wrapped.
      Overrides:
      getMap in class AbstractMultiValuedMap<K,V>
      Returns:
      the wrapped map
    • createCollection

      protected abstract Set<V> createCollection()
      Creates a new value collection using the provided factory.
      Specified by:
      createCollection in class AbstractMultiValuedMap<K,V>
      Returns:
      a new list
    • get

      public Set<V> get(K key)
      Gets the set of values associated with the specified key. This would return an empty set in case the mapping is not present
      Specified by:
      get in interface MultiValuedMap<K,V>
      Specified by:
      get in interface SetValuedMap<K,V>
      Overrides:
      get in class AbstractMultiValuedMap<K,V>
      Parameters:
      key - the key to retrieve
      Returns:
      the Set of values, will return an empty Set for no mapping
    • remove

      public Set<V> remove(Object key)
      Removes all values associated with the specified key.

      A subsequent get(Object) would return an empty set.

      Specified by:
      remove in interface MultiValuedMap<K,V>
      Specified by:
      remove in interface SetValuedMap<K,V>
      Overrides:
      remove in class AbstractMultiValuedMap<K,V>
      Parameters:
      key - the key to remove values from
      Returns:
      the Set of values removed, will return an empty, unmodifiable set for no mapping found.