Class AbstractSynchronizedMultimap<K,​V>

    • Field Detail

      • lock

        private final java.lang.Object lock
    • Constructor Detail

      • AbstractSynchronizedMultimap

        protected AbstractSynchronizedMultimap​(MutableMultimap<K,​V> multimap,
                                               java.lang.Object newLock)
      • AbstractSynchronizedMultimap

        protected AbstractSynchronizedMultimap​(MutableMultimap<K,​V> multimap)
    • Method Detail

      • getLock

        protected java.lang.Object getLock()
      • writeReplace

        protected java.lang.Object writeReplace()
      • equals

        public boolean equals​(java.lang.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 java.lang.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 java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • 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​(java.lang.Object key,
                              java.lang.Object value)
        Specified by:
        remove in interface MutableMultimap<K,​V>
      • putAllPairs

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

        public boolean putAll​(K key,
                              java.lang.Iterable<? extends V> values)
        Specified by:
        putAll 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 RichIterable<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​(java.lang.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​(java.lang.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​(java.lang.Object key,
                                           java.lang.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
      • 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>
      • toMap

        public <R extends java.util.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 RichIterable<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 RichIterable<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