Class AbstractMultimap<K,V,C extends RichIterable<V>>
- All Implemented Interfaces:
Multimap<K,V>
- Direct Known Subclasses:
AbstractImmutableMultimap
,AbstractMutableMultimap
public abstract class AbstractMultimap<K,V,C extends RichIterable<V>> extends Object implements Multimap<K,V>
-
Constructor Summary
Constructors Constructor Description AbstractMultimap()
-
Method Summary
Modifier and Type Method Description <K2, V2, R extends MutableMultimap<K2, V2>>
RcollectKeyMultiValues(Function<? super K,? extends K2> keyFunction, Function<? super V,? extends V2> valueFunction, R target)
Same as the collectKeyMultiValues method but uses the specified target multimap for the results.<K2, V2, R extends MutableMultimap<K2, V2>>
RcollectKeysValues(Function2<? super K,? super V,Pair<K2,V2>> function, R target)
Same as the collect method but uses the specified target multimap for the results.<V2, R extends MutableMultimap<K, V2>>
RcollectValues(Function<? super V,? extends V2> function, R target)
Same as the collect method but uses the specified target multimap for the results.boolean
containsKey(Object key)
Returnstrue
if any values are mapped to the specified key.boolean
containsKeyAndValue(Object key, Object value)
Returnstrue
if the specified key-value pair is mapped.boolean
containsValue(Object value)
Returnstrue
if any key is mapped to the specified value.boolean
equals(Object object)
Compares the specified object with this Multimap for equality.void
forEachKey(Procedure<? super K> procedure)
Calls theprocedure
with each key.void
forEachKeyMultiValues(Procedure2<? super K,? super Iterable<V>> procedure)
Calls theprocedure
with each key-Iterable[value].void
forEachKeyValue(Procedure2<? super K,? super V> procedure)
Calls theprocedure
with each key-value pair.void
forEachValue(Procedure<? super V> procedure)
Calls the procedure with each value.int
hashCode()
Returns the hash code for this multimap.Bag<K>
keyBag()
Returns aBag
of keys with the count corresponding to the number of mapped values.RichIterable<Pair<K,RichIterable<V>>>
keyMultiValuePairsView()
Returns a lazy view of the pair of a key and and a lazy view of the values mapped to that key.RichIterable<K>
keysView()
Returns a lazy view of the unique keys.RichIterable<Pair<K,V>>
keyValuePairsView()
Returns a lazy view of all of the key/value pairs.RichIterable<RichIterable<V>>
multiValuesView()
Returns an unmodifiable view of all of the values mapped to each key.boolean
notEmpty()
Returnstrue
if there is at least one entry.<R extends MutableMultimap<K, V>>
RrejectKeysMultiValues(Predicate2<? super K,? super Iterable<V>> predicate, R target)
Same as the reject method but uses the specified target multimap for the results.<R extends MutableMultimap<K, V>>
RrejectKeysValues(Predicate2<? super K,? super V> predicate, R target)
Same as the reject method but uses the specified target multimap for the results.<R extends MutableMultimap<K, V>>
RselectKeysMultiValues(Predicate2<? super K,? super Iterable<V>> predicate, R target)
Same as the select method but uses the specified target multimap for the results.<R extends MutableMultimap<K, V>>
RselectKeysValues(Predicate2<? super K,? super V> predicate, R target)
Same as the select method but uses the specified target multimap for the results.String
toString()
Returns a string representation of the multimap, generated by callingtoString
on the map returned byMultimap.toMap()
.RichIterable<V>
valuesView()
Returns a lazy flattened view of all the values.Methods inherited from interface org.eclipse.collections.api.multimap.Multimap
collectKeyMultiValues, collectKeysValues, collectValues, flip, get, isEmpty, keySet, newEmpty, rejectKeysMultiValues, rejectKeysValues, selectKeysMultiValues, selectKeysValues, size, sizeDistinct, toImmutable, toMap, toMap, toMutable
-
Constructor Details
-
AbstractMultimap
public AbstractMultimap()
-
-
Method Details
-
containsKey
Description copied from interface:Multimap
Returnstrue
if any values are mapped to the specified key.- Specified by:
containsKey
in interfaceMultimap<K,V>
- Parameters:
key
- the key to search for
-
containsValue
Description copied from interface:Multimap
Returnstrue
if any key is mapped to the specified value.- Specified by:
containsValue
in interfaceMultimap<K,V>
- Parameters:
value
- the value to search for
-
containsKeyAndValue
Description copied from interface:Multimap
Returnstrue
if the specified key-value pair is mapped.- Specified by:
containsKeyAndValue
in interfaceMultimap<K,V>
- Parameters:
key
- the key to search forvalue
- the value to search for
-
keysView
Description copied from interface:Multimap
Returns a lazy view of the unique keys. -
multiValuesView
Description copied from interface:Multimap
Returns an unmodifiable view of all of the values mapped to each key.- Specified by:
multiValuesView
in interfaceMultimap<K,V>
-
keyBag
Description copied from interface:Multimap
Returns aBag
of keys with the count corresponding to the number of mapped values. -
valuesView
Description copied from interface:Multimap
Returns a lazy flattened view of all the values.- Specified by:
valuesView
in interfaceMultimap<K,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 interfaceMultimap<K,V>
-
keyValuePairsView
Description copied from interface:Multimap
Returns a lazy view of all of the key/value pairs.- Specified by:
keyValuePairsView
in interfaceMultimap<K,V>
-
equals
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. -
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()
. -
toString
Returns a string representation of the multimap, generated by callingtoString
on the map returned byMultimap.toMap()
. -
notEmpty
public boolean notEmpty()Description copied from interface:Multimap
Returnstrue
if there is at least one entry. -
forEachValue
Description copied from interface:Multimap
Calls the procedure with each value.Given a Multimap with the contents:
{"key1" : ["val1", "val2", "val2"], "key2" : ["val3"]}
["val1", "val2", "val2", "val3"]
- Specified by:
forEachValue
in interfaceMultimap<K,V>
-
forEachKey
Description copied from interface:Multimap
Calls theprocedure
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 interfaceMultimap<K,V>
-
forEachKeyValue
Description copied from interface:Multimap
Calls theprocedure
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 interfaceMultimap<K,V>
-
forEachKeyMultiValues
Description copied from interface:Multimap
Calls theprocedure
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 interfaceMultimap<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 interfaceMultimap<K,V>
- Parameters:
predicate
- aPredicate2
to use as the select criteriatarget
- the Multimap to append to for all elements in thisMultimap
that satisfy thepredicate
- 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 interfaceMultimap<K,V>
- Parameters:
predicate
- aPredicate2
to use as the reject criteriatarget
- the Multimap to append to for all elements in thisMultimap
that don't satisfy thepredicate
- Returns:
target
, which contains appended elements that don't satisfy thepredicate
-
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 interfaceMultimap<K,V>
- Parameters:
predicate
- aPredicate2
to use as the select criteriatarget
- the Multimap to append to for all elements in thisMultimap
that satisfy thepredicate
- 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 interfaceMultimap<K,V>
- Parameters:
predicate
- aPredicate2
to use as the reject criteriatarget
- the Multimap to append to for all elements in thisMultimap
that don't satisfy thepredicate
- Returns:
target
, which contains appended elements that don't satisfy thepredicate
-
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 interfaceMultimap<K,V>
- Parameters:
function
- aFunction2
to use for transformationtarget
- the Multimap to append for all elements in thisMultimap
that are evaluated infunction
- 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 interfaceMultimap<K,V>
- Parameters:
keyFunction
-Function
to use transformation to get the keyvalueFunction
-Function
to use transformation to get the valuestarget
- the Multimap to append for all elements in thisMultimap
that are evaluated inkeyFunction
andvalueFunction
- 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 interfaceMultimap<K,V>
- Parameters:
function
- aFunction
to use for transformationtarget
- the Multimap to append for all elements in thisMultimap
that are evaluated infunction
- Returns:
target
, which contains appended elements as a result of the transformation
-