Class AbstractSynchronizedMultimap<K,​V>

java.lang.Object
org.eclipse.collections.impl.multimap.AbstractSynchronizedMultimap<K,​V>
All Implemented Interfaces:
Multimap<K,​V>, MutableMultimap<K,​V>
Direct Known Subclasses:
SynchronizedBagMultimap, SynchronizedListMultimap, SynchronizedSetMultimap, SynchronizedSortedBagMultimap, SynchronizedSortedSetMultimap

public abstract class AbstractSynchronizedMultimap<K,​V>
extends Object
implements MutableMultimap<K,​V>
  • Method Details

    • equals

      public boolean equals​(Object obj)
      Description copied from interface: Multimap
      Compares the specified object with this Multimap for equality.

      Two Multimaps are equal when their map views (as returned by Multimap.toMap()) are also equal.

      In general, two Multimaps with identical key-value mappings may or may not be equal, depending on the type of the collections holding the values. If the backing collections are Sets, then two instances with the same key-value mappings are equal, but if the backing collections are Lists, equality depends on the ordering of the values for each key.

      Any two empty Multimaps are equal, because they both have empty Multimap.toMap() views.

      Specified by:
      equals in interface Multimap<K,​V>
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Description copied from interface: Multimap
      Returns the hash code for this Multimap.

      The hash code of a Multimap is defined as the hash code of the map view, as returned by Multimap.toMap().

      Specified by:
      hashCode in interface Multimap<K,​V>
      Overrides:
      hashCode in class Object
    • toString

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

      public boolean put​(K key, V value)
      Specified by:
      put in interface MutableMultimap<K,​V>
    • add

      public boolean add​(Pair<? extends K,​? extends V> keyValuePair)
      Description copied from interface: MutableMultimap
      Modification operation similar to put, however, takes the key-value pair as the input.
      Specified by:
      add in interface MutableMultimap<K,​V>
      Parameters:
      keyValuePair - key value pair to add in the multimap
      See Also:
      MutableMultimap.put(Object, Object)
    • remove

      public boolean remove​(Object key, Object value)
      Specified by:
      remove in interface MutableMultimap<K,​V>
    • putAllPairs

      public boolean putAllPairs​(Pair<? extends K,​? extends V>... pairs)
      Specified by:
      putAllPairs in interface MutableMultimap<K,​V>
    • putAllPairs

      public boolean putAllPairs​(Iterable<? extends Pair<? extends K,​? extends V>> pairs)
      Specified by:
      putAllPairs in interface MutableMultimap<K,​V>
    • putAll

      public boolean putAll​(K key, Iterable<? extends V> values)
      Specified by:
      putAll in interface MutableMultimap<K,​V>
    • putAll

      public <KK extends K,​ VV extends V> boolean putAll​(Multimap<KK,​VV> multimap)
      Specified by:
      putAll in interface MutableMultimap<K,​V>
    • clear

      public void clear()
      Specified by:
      clear in interface MutableMultimap<K,​V>
    • isEmpty

      public boolean isEmpty()
      Description copied from interface: Multimap
      Returns true if there are no entries.
      Specified by:
      isEmpty in interface Multimap<K,​V>
    • notEmpty

      public boolean notEmpty()
      Description copied from interface: Multimap
      Returns true if there is at least one entry.
      Specified by:
      notEmpty in interface Multimap<K,​V>
    • forEachValue

      public void forEachValue​(Procedure<? super V> procedure)
      Description copied from interface: Multimap
      Calls the procedure with each value.

      Given a Multimap with the contents:

      {"key1" : ["val1", "val2", "val2"], "key2" : ["val3"]}

      The given procedure would be invoked with the parameters:

      ["val1", "val2", "val2", "val3"]

      Specified by:
      forEachValue in interface Multimap<K,​V>
    • forEachKey

      public void forEachKey​(Procedure<? super K> procedure)
      Description copied from interface: Multimap
      Calls the procedure with each key.

      Given a Multimap with the contents:

      {"key1" : ["val1", "val2", "val2"], "key2" : ["val3"]}

      The given procedure would be invoked with the parameters:

      ["key1", "key2"]

      Specified by:
      forEachKey in interface Multimap<K,​V>
    • forEachKeyValue

      public void forEachKeyValue​(Procedure2<? super K,​? super V> procedure)
      Description copied from interface: Multimap
      Calls the procedure with each key-value pair.

      Given a Multimap with the contents:

      {"key1" : ["val1", "val2", "val2"], "key2" : ["val3"]}

      The given procedure would be invoked with the parameters:

      [["key1", "val1"], ["key1", "val2"], ["key1", "val2"], ["key2", "val3"]]

      Specified by:
      forEachKeyValue in interface Multimap<K,​V>
    • forEachKeyMultiValues

      public void forEachKeyMultiValues​(Procedure2<? super K,​? super Iterable<V>> procedure)
      Description copied from interface: Multimap
      Calls the procedure with each key-Iterable[value].

      Given a Multimap with the contents:

      {"key1" : ["val1", "val2", "val2"], "key2" : ["val3"]}

      The given procedure would be invoked with the parameters:

      [["key1", {@link RichIterable["val1", "val2", "val2"]}], ["key2", {@link RichIterable["val3"]}]]

      Specified by:
      forEachKeyMultiValues in interface Multimap<K,​V>
    • size

      public int size()
      Description copied from interface: Multimap
      Returns the number of key-value entry pairs.

      This method is implemented with O(1) (constant-time) performance.

      Specified by:
      size in interface Multimap<K,​V>
    • sizeDistinct

      public int sizeDistinct()
      Description copied from interface: Multimap
      Returns the number of distinct keys.
      Specified by:
      sizeDistinct in interface Multimap<K,​V>
    • containsKey

      public boolean containsKey​(Object key)
      Description copied from interface: Multimap
      Returns true if any values are mapped to the specified key.
      Specified by:
      containsKey in interface Multimap<K,​V>
      Parameters:
      key - the key to search for
    • containsValue

      public boolean containsValue​(Object value)
      Description copied from interface: Multimap
      Returns true if any key is mapped to the specified value.
      Specified by:
      containsValue in interface Multimap<K,​V>
      Parameters:
      value - the value to search for
    • containsKeyAndValue

      public boolean containsKeyAndValue​(Object key, Object value)
      Description copied from interface: Multimap
      Returns true if the specified key-value pair is mapped.
      Specified by:
      containsKeyAndValue in interface Multimap<K,​V>
      Parameters:
      key - the key to search for
      value - the value to search for
    • keysView

      public RichIterable<K> keysView()
      Description copied from interface: Multimap
      Returns a lazy view of the unique keys.
      Specified by:
      keysView in interface Multimap<K,​V>
    • keySet

      public SetIterable<K> keySet()
      Description copied from interface: Multimap
      Returns a unmodifiable SetIterable of keys with O(1) complexity.
      Specified by:
      keySet in interface Multimap<K,​V>
    • keyBag

      public Bag<K> keyBag()
      Description copied from interface: Multimap
      Returns a Bag of keys with the count corresponding to the number of mapped values.
      Specified by:
      keyBag in interface Multimap<K,​V>
    • multiValuesView

      public RichIterable<RichIterable<V>> multiValuesView()
      Description copied from interface: Multimap
      Returns an unmodifiable view of all of the values mapped to each key.
      Specified by:
      multiValuesView in interface Multimap<K,​V>
    • valuesView

      public RichIterable<V> valuesView()
      Description copied from interface: Multimap
      Returns a lazy flattened view of all the values.
      Specified by:
      valuesView in interface Multimap<K,​V>
    • keyMultiValuePairsView

      public RichIterable<Pair<K,​RichIterable<V>>> keyMultiValuePairsView()
      Description copied from interface: Multimap
      Returns a lazy view of the pair of a key and and a lazy view of the values mapped to that key.
      Specified by:
      keyMultiValuePairsView in interface Multimap<K,​V>
    • keyValuePairsView

      public RichIterable<Pair<K,​V>> keyValuePairsView()
      Description copied from interface: Multimap
      Returns a lazy view of all of the key/value pairs.
      Specified by:
      keyValuePairsView in interface Multimap<K,​V>
    • toMap

      public MutableMap<K,​RichIterable<V>> toMap()
      Description copied from interface: Multimap
      Returns a new MutableMap of keys from this Multimap to the mapped values as a RichIterable.
      Specified by:
      toMap in interface Multimap<K,​V>
    • toMap

      public <R extends Collection<V>> MutableMap<K,​R> toMap​(Function0<R> collectionFactory)
      Description copied from interface: Multimap
      Returns a new MutableMap of keys from this Multimap to the mapped values as a RichIterable.
      Specified by:
      toMap in interface Multimap<K,​V>
      Parameters:
      collectionFactory - used to create the collections that hold the values and affects the return type
    • selectKeysValues

      public <R extends MutableMultimap<K,​ V>> R selectKeysValues​(Predicate2<? super K,​? super V> predicate, R target)
      Description copied from interface: Multimap
      Same as the select method but uses the specified target multimap for the results.
      e.g.
       return multimap.selectKeysValues(new Predicate2<Integer, Person>()
       {
           public boolean accept(Integer age, Person person)
           {
               return (age >= 18)
                        && (person.getAddress().getCity().equals("Metuchen"));
           }
       }, FastListMultimap.newMultimap());
       
      Specified by:
      selectKeysValues in interface Multimap<K,​V>
      Parameters:
      predicate - a Predicate2 to use as the select criteria
      target - the Multimap to append to for all elements in this Multimap that satisfy the predicate
      Returns:
      target, which contains appended elements as a result of the select criteria
    • rejectKeysValues

      public <R extends MutableMultimap<K,​ V>> R rejectKeysValues​(Predicate2<? super K,​? super V> predicate, R target)
      Description copied from interface: Multimap
      Same as the reject method but uses the specified target multimap for the results.
      e.g.
       return multimap.rejectKeysValues(new Predicate2<Integer, Person>()
       {
           public boolean accept(Integer age, Person person)
           {
               return (age >= 18)
                        && (person.getAddress().getCity().equals("Metuchen"));
           }
       }, FastListMultimap.newMultimap());
       
      Specified by:
      rejectKeysValues in interface Multimap<K,​V>
      Parameters:
      predicate - a Predicate2 to use as the reject criteria
      target - the Multimap to append to for all elements in this Multimap that don't satisfy the predicate
      Returns:
      target, which contains appended elements that don't satisfy the predicate
    • selectKeysMultiValues

      public <R extends MutableMultimap<K,​ V>> R selectKeysMultiValues​(Predicate2<? super K,​? super Iterable<V>> predicate, R target)
      Description copied from interface: Multimap
      Same as the select method but uses the specified target multimap for the results.
      e.g.
       return multimap.selectKeysMultiValues(new Predicate2<Integer, Iterable<Person>>()
       {
           public boolean accept(Integer age, Iterable<Person> values)
           {
               return (age >= 18)
                        && ((RichIterable<Person>)values.size() >= 2);
           }
       }, FastListMultimap.newMultimap());
       
      Specified by:
      selectKeysMultiValues in interface Multimap<K,​V>
      Parameters:
      predicate - a Predicate2 to use as the select criteria
      target - the Multimap to append to for all elements in this Multimap that satisfy the predicate
      Returns:
      target, which contains appended elements as a result of the select criteria
    • rejectKeysMultiValues

      public <R extends MutableMultimap<K,​ V>> R rejectKeysMultiValues​(Predicate2<? super K,​? super Iterable<V>> predicate, R target)
      Description copied from interface: Multimap
      Same as the reject method but uses the specified target multimap for the results.
      e.g.
       return multimap.rejectKeysMultiValues(new Predicate2<Integer, Iterable<Person>>()
       {
           public boolean accept(Integer age, Iterable<Person> values)
           {
               return (age >= 18)
                        && ((RichIterable<Person>)values.size() >= 2);
           }
       }, FastListMultimap.newMultimap());
       
      Specified by:
      rejectKeysMultiValues in interface Multimap<K,​V>
      Parameters:
      predicate - a Predicate2 to use as the reject criteria
      target - the Multimap to append to for all elements in this Multimap that don't satisfy the predicate
      Returns:
      target, which contains appended elements that don't satisfy the predicate
    • collectKeysValues

      public <K2,​ V2,​ R extends MutableMultimap<K2,​ V2>> R collectKeysValues​(Function2<? super K,​? super V,​Pair<K2,​V2>> function, R target)
      Description copied from interface: Multimap
      Same as the collect method but uses the specified target multimap for the results.
      e.g.
       return multimap.collectKeysValues(new Function2<Integer, Person, Pair<String, String>>()
       {
           public Pair<String, String> valueOf(Integer age, Person person)
           {
               return Tuples.pair(age.toString(), person.getLastName());
           }
       }, HashBagMultimap.<String, String>newMultimap());
       
      Specified by:
      collectKeysValues in interface Multimap<K,​V>
      Parameters:
      function - a Function2 to use for transformation
      target - the Multimap to append for all elements in this Multimap that are evaluated in function
      Returns:
      target, which contains appended elements as a result of the transformation
    • collectKeyMultiValues

      public <K2,​ V2,​ R extends MutableMultimap<K2,​ V2>> R collectKeyMultiValues​(Function<? super K,​? extends K2> keyFunction, Function<? super V,​? extends V2> valueFunction, R target)
      Description copied from interface: Multimap
      Same as the collectKeyMultiValues method but uses the specified target multimap for the results.
      e.g.
       return multimap.collectKeyMultiValues(each -> each + 1, Person::getLastName, HashBagMultimap.<Integer, String>newMultimap());
       
      Specified by:
      collectKeyMultiValues in interface Multimap<K,​V>
      Parameters:
      keyFunction - Function to use transformation to get the key
      valueFunction - Function to use transformation to get the values
      target - the Multimap to append for all elements in this Multimap that are evaluated in keyFunction and valueFunction
      Returns:
      target, which contains appended elements as a result of the transformation
    • collectValues

      public <V2,​ R extends MutableMultimap<K,​ V2>> R collectValues​(Function<? super V,​? extends V2> function, R target)
      Description copied from interface: Multimap
      Same as the collect method but uses the specified target multimap for the results.
      e.g.
       return multimap.collectValues(new Function<Person, String>()
       {
           public String valueOf(Person person)
           {
               return person.getLastName();
           }
       }, FastListMultimap.<Integer, String>newMultimap());
       
      Specified by:
      collectValues in interface Multimap<K,​V>
      Parameters:
      function - a Function to use for transformation
      target - the Multimap to append for all elements in this Multimap that are evaluated in function
      Returns:
      target, which contains appended elements as a result of the transformation