Map that can associate multiple values for keys.
Unlike Map however, this interface is read-only so the results of access methods such as get(Object) return a view onto the values associated with that key. The MutableMultimap sub-interface
provides methods to mutate the collection.
The advantages to using this container over a Map<K, Collection<V>> is that all of the handling of the
value collection can be done automatically. It also allows implementations to further specialize in how duplicate
values will be handled. Value collections with list semantics would allow duplicate values for a key, while those
implementing set semantics would not. The value collections can never be empty.
Internal iteration methods for keys and values (singly - forEachKey(Procedure), forEachValue(Procedure),
and together - forEachKeyValue(Procedure2)), forEachKeyMultiValues(Procedure2)) are provided to allow flexible
browsing of the collection's contents. Similarly, views also are provided for keys (keysView()), values
(valuesView()) and the combination thereof (keyValuePairsView(), keyMultiValuePairsView()).
| Modifier and Type | Method and Description |
|---|---|
| public <K2, V2> Multimap | Returns: a newMultimap, which contains elements as a result of the transformationFunction to use transformation to get the keyFunction to use transformation to get the valuesReturns a new multimap with the results of applying the specified keyFunction and valueFunction on each key and corresponding values of the source multimap. |
| public <K2, V2, R extends MutableMultimap | Returns: target, which contains appended elements as a result of the transformationFunction to use transformation to get the keyFunction to use transformation to get the valuesthe Multimap to append for all elements in this target)Multimap that are evaluated in keyFunction and valueFunctionSame as the collectKeyMultiValues method but uses the specified target multimap for the results. |
| public <K2, V2> Multimap | Returns: Multimap, which contains elements as a result of the transformationa function)Function2 to use for transformationReturns a new multimap with the results of applying the specified function on each key and value of the source multimap. |
| public <K2, V2, R extends MutableMultimap | Returns: target, which contains appended elements as a result of the transformationa function, R Function2 to use for transformationthe Multimap to append for all elements in this target)Multimap that are evaluated in functionSame as the collect method but uses the specified target multimap for the results. |
| public <V2> Multimap | Returns: Multimap, which contains elements as a result of the transformationa function)Function to use for transformationReturns a new multimap with the results of applying the specified function on each value of the source multimap. |
| public <V2, R extends MutableMultimap | Returns: target, which contains appended elements as a result of the transformationa function, R Function to use for transformationthe Multimap to append for all elements in this target)Multimap that are evaluated in functionSame as the collect method but uses the specified target multimap for the results. |
| public boolean | containsKey(Object
the key to search for key)Returns |
| public boolean | containsKeyAndValue(Object
the key to search for key, Object the value to search for value)Returns |
| public boolean | containsValue(Object
the value to search for value)Returns |
| public boolean | |
| public Multimap | |
| public void | |
| public void | forEachKeyMultiValues(Procedure2<? super K, ? super RichIterable<V>> procedure)
Calls the |
| public void | forEachKeyValue(Procedure2<? super K, ? super V> procedure)
Calls the |
| public void | |
| public RichIterable | |
| public int | |
| public boolean | |
| public Bag | |
| public RichIterable | keyMultiValuePairsView()
Returns a lazy view of the pair of a key and a lazy view of the values mapped to that key. |
| public SetIterable | |
| public RichIterable | |
| public RichIterable | |
| public RichIterable | |
| public Multimap | newEmpty()
Creates a new instance of the same implementation type, using the default capacity and growth parameters. |
| public boolean | |
| public Multimap | Returns: Multimap, which contains elements that don't satisfy the predicatea predicate)Predicate2 to use as the reject criteriaReturns all elements of the source multimap that don't satisfy the predicate. |
| public <R extends MutableMultimap | Returns: target, which contains appended elements that don't satisfy the predicatea predicate, R Predicate2 to use as the reject criteriathe Multimap to append to for all elements in this target)Multimap that don't satisfy the predicateSame as the reject method but uses the specified target multimap for the results. |
| public Multimap | Returns: Multimap, which contains elements that don't satisfy the predicatea predicate)Predicate2 to use as the reject criteriaReturns all elements of the source multimap that don't satisfy the predicate. |
| public <R extends MutableMultimap | Returns: target, which contains appended elements that don't satisfy the predicatea predicate, R Predicate2 to use as the reject criteriathe Multimap to append to for all elements in this target)Multimap that don't satisfy the predicateSame as the reject method but uses the specified target multimap for the results. |
| public Multimap | Returns: Multimap, which contains elements as a result of the select criteriaa predicate)Predicate2 to use as the select criteriaReturns all elements of the source multimap that satisfies the predicate. |
| public <R extends MutableMultimap | Returns: target, which contains appended elements as a result of the select criteriaa predicate, R Predicate2 to use as the select criteriathe Multimap to append to for all elements in this target)Multimap that satisfy the predicateSame as the select method but uses the specified target multimap for the results. |
| public Multimap | Returns: Multimap, which contains elements as a result of the select criteriaa predicate)Predicate2 to use as the select criteriaReturns all elements of the source multimap that satisfies the predicate. |
| public <R extends MutableMultimap | Returns: target, which contains appended elements as a result of the select criteriaa predicate, R Predicate2 to use as the select criteriathe Multimap to append to for all elements in this target)Multimap that satisfy the predicateSame as the select method but uses the specified target multimap for the results. |
| public int | |
| public int | |
| public ImmutableMultimap | |
| public MutableMap | |
| public <R extends Collection | toMap(Function0<R>
used to create the collections that hold the values and affects the return type collectionFactory)Returns a new |
| public MutableMultimap | |
| public RichIterable |
| collectKeyMultiValues | back to summary |
|---|---|
| public <K2, V2> Multimap Returns a new multimap with the results of applying the specified keyFunction and valueFunction on each key and corresponding values of the source multimap. This method is also commonly called transform or map. e.g. return multimap.collectKeyMultiValues(each -> each + 1, Person::getLastName);
| |
| collectKeyMultiValues | back to summary |
|---|---|
| public <K2, V2, R extends MutableMultimap 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());
| |
| collectKeysValues | back to summary |
|---|---|
| public <K2, V2> Multimap Returns a new multimap with the results of applying the specified function on each key and value of the source multimap. This method is also commonly called transform or map. 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());
}
});
| |
| collectKeysValues | back to summary |
|---|---|
| public <K2, V2, R extends MutableMultimap 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());
| |
| collectValues | back to summary |
|---|---|
| public <V2> Multimap Returns a new multimap with the results of applying the specified function on each value of the source multimap. This method is also commonly called transform or map. e.g.
return multimap.collectValues(new Function<Person, String>()
{
public String valueOf(Person person)
{
return person.getLastName();
}
});
| |
| collectValues | back to summary |
|---|---|
| public <V2, R extends MutableMultimap 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());
| |
| containsKey | back to summary |
|---|---|
| public boolean containsKey(Object key) Returns
| |
| containsKeyAndValue | back to summary |
|---|---|
| public boolean containsKeyAndValue(Object key, Object value) Returns | |
| containsValue | back to summary |
|---|---|
| public boolean containsValue(Object value) Returns
| |
| equals | back to summary |
|---|---|
| public boolean equals(Object obj) Compares the specified object with this Multimap for equality. Two Multimaps are equal when their map views (as returned by 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
| |
| flip | back to summary |
|---|---|
| public Multimap Given a Multimap from Domain
| |
| forEachKey | back to summary |
|---|---|
| public void forEachKey(Procedure<? super K> procedure) Calls the Given a Multimap with the contents:
The given procedure would be invoked with the parameters:
| |
| forEachKeyMultiValues | back to summary |
|---|---|
| public void forEachKeyMultiValues(Procedure2<? super K, ? super RichIterable<V>> procedure) Calls the Given a Multimap with the contents:
The given procedure would be invoked with the parameters:
| |
| forEachKeyValue | back to summary |
|---|---|
| public void forEachKeyValue(Procedure2<? super K, ? super V> procedure) Calls the Given a Multimap with the contents:
The given procedure would be invoked with the parameters:
| |
| forEachValue | back to summary |
|---|---|
| public void forEachValue(Procedure<? super V> procedure) Calls the procedure with each value. Given a Multimap with the contents:
| |
| get | back to summary |
|---|---|
| public RichIterable Returns a view of all values associated with the given key. If the given key does not exist, an empty
| |
| hashCode | back to summary |
|---|---|
| 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
| |
| isEmpty | back to summary |
|---|---|
| public boolean isEmpty() Returns | |
| keyBag | back to summary |
|---|---|
| public Bag Returns a | |
| keyMultiValuePairsView | back to summary |
|---|---|
| public RichIterable Returns a lazy view of the pair of a key and a lazy view of the values mapped to that key. | |
| keySet | back to summary |
|---|---|
| public SetIterable Returns an unmodifiable | |
| keysView | back to summary |
|---|---|
| public RichIterable Returns a lazy view of the unique keys. | |
| keyValuePairsView | back to summary |
|---|---|
| public RichIterable Returns a lazy view of all the key/value pairs. | |
| multiValuesView | back to summary |
|---|---|
| public RichIterable Returns an unmodifiable view of all the values mapped to each key. | |
| newEmpty | back to summary |
|---|---|
| public Multimap Creates a new instance of the same implementation type, using the default capacity and growth parameters. | |
| notEmpty | back to summary |
|---|---|
| public boolean notEmpty() Returns | |
| rejectKeysMultiValues | back to summary |
|---|---|
| public Multimap Returns all elements of the source multimap that don't satisfy the predicate. 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);
}
});
| |
| rejectKeysMultiValues | back to summary |
|---|---|
| public <R extends MutableMultimap 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());
| |
| rejectKeysValues | back to summary |
|---|---|
| public Multimap Returns all elements of the source multimap that don't satisfy the predicate. e.g.
return multimap.rejectKeysValues(new Predicate2<Integer, Person>()
{
public boolean accept(Integer age, Person person)
{
return (age >= 18)
&& (person.getAddress().getCity().equals("Metuchen"));
}
});
| |
| rejectKeysValues | back to summary |
|---|---|
| public <R extends MutableMultimap 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());
| |
| selectKeysMultiValues | back to summary |
|---|---|
| public Multimap Returns all elements of the source multimap that satisfies the predicate. This method is also commonly called filter. 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);
}
});
| |
| selectKeysMultiValues | back to summary |
|---|---|
| public <R extends MutableMultimap 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());
| |
| selectKeysValues | back to summary |
|---|---|
| public Multimap Returns all elements of the source multimap that satisfies the predicate. This method is also commonly called filter. e.g.
return multimap.selectKeysValues(new Predicate2<Integer, Person>()
{
public boolean accept(Integer age, Person person)
{
return (age >= 18)
&& (person.getAddress().getCity().equals("Metuchen"));
}
});
| |
| selectKeysValues | back to summary |
|---|---|
| public <R extends MutableMultimap 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());
| |
| size | back to summary |
|---|---|
| public int size() Returns the number of key-value entry pairs. This method is implemented with O(1) (constant-time) performance. | |
| sizeDistinct | back to summary |
|---|---|
| public int sizeDistinct() Returns the number of distinct keys. | |
| toImmutable | back to summary |
|---|---|
| public ImmutableMultimap Returns an immutable copy of this Multimap if it is not already immutable. If the Multimap is immutable, it will return itself. The returned Multimap will be | |
| toMap | back to summary |
|---|---|
| public MutableMap Returns a new | |
| toMap | back to summary |
|---|---|
| public <R extends Collection Returns a new
| |
| toMutable | back to summary |
|---|---|
| public MutableMultimap Returns a mutable copy of this Multimap. | |
| valuesView | back to summary |
|---|---|
| public RichIterable Returns a lazy flattened view of all the values. | |