Class AbstractMultimap<K,​V,​C extends RichIterable<V>>

    • Constructor Detail

      • AbstractMultimap

        public AbstractMultimap()
    • Method Detail

      • createCollection

        protected abstract C createCollection()
        Creates the collection of values for a single key.

        Collections with weak, soft, or phantom references are not supported. Each call to createCollection should create a new instance.

        The returned collection class determines whether duplicate key-value pairs are allowed.

        Returns:
        an empty collection of values
      • 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>
      • equals

        public boolean equals​(java.lang.Object object)
        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()
        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
        See Also:
        Map.hashCode()
      • toString

        public java.lang.String toString()
        Returns a string representation of the multimap, generated by calling toString on the map returned by Multimap.toMap().
        Overrides:
        toString in class java.lang.Object
        Returns:
        a string representation of the multimap
      • 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>
      • 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