public abstract class AbstractMultimap<K,V,C extends RichIterable<V>> extends Object implements Multimap<K,V>
Constructor and Description |
---|
AbstractMultimap() |
Modifier and Type | Method and Description |
---|---|
<K2,V2,R extends MutableMultimap<K2,V2>> |
collectKeysValues(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>> |
collectValues(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)
Returns
true if any values are mapped to the specified key. |
boolean |
containsKeyAndValue(Object key,
Object value)
Returns
true if the specified key-value pair is mapped. |
boolean |
containsValue(Object value)
Returns
true 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 the
procedure with each key. |
void |
forEachKeyMultiValues(Procedure2<K,? super Iterable<V>> procedure)
Calls the
procedure with each key-Iterable[value]. |
void |
forEachKeyValue(Procedure2<K,V> procedure)
Calls the
procedure 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 a
Bag 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()
Returns
true if there is at least one entry. |
<R extends MutableMultimap<K,V>> |
rejectKeysMultiValues(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>> |
rejectKeysValues(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>> |
selectKeysMultiValues(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>> |
selectKeysValues(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 calling
toString on the map returned by Multimap.toMap() . |
RichIterable<V> |
valuesView()
Returns a lazy flattened view of all the values.
|
collectKeysValues, collectValues, flip, get, isEmpty, newEmpty, rejectKeysMultiValues, rejectKeysValues, selectKeysMultiValues, selectKeysValues, size, sizeDistinct, toImmutable, toMap, toMap, toMutable
public boolean containsKey(Object key)
Multimap
true
if any values are mapped to the specified key.containsKey
in interface Multimap<K,V>
key
- the key to search forpublic boolean containsValue(Object value)
Multimap
true
if any key is mapped to the specified value.containsValue
in interface Multimap<K,V>
value
- the value to search forpublic boolean containsKeyAndValue(Object key, Object value)
Multimap
true
if the specified key-value pair is mapped.containsKeyAndValue
in interface Multimap<K,V>
key
- the key to search forvalue
- the value to search forpublic RichIterable<K> keysView()
Multimap
public RichIterable<RichIterable<V>> multiValuesView()
Multimap
multiValuesView
in interface Multimap<K,V>
public Bag<K> keyBag()
Multimap
Bag
of keys with the count corresponding to the number of mapped values.public RichIterable<V> valuesView()
Multimap
valuesView
in interface Multimap<K,V>
public RichIterable<Pair<K,RichIterable<V>>> keyMultiValuePairsView()
Multimap
keyMultiValuePairsView
in interface Multimap<K,V>
public RichIterable<Pair<K,V>> keyValuePairsView()
Multimap
keyValuePairsView
in interface Multimap<K,V>
public boolean equals(Object object)
Multimap
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.
public int hashCode()
The hash code of a multimap is defined as the hash code of the map view,
as returned by Multimap.toMap()
.
public String toString()
toString
on the map returned by Multimap.toMap()
.public boolean notEmpty()
Multimap
true
if there is at least one entry.public void forEachValue(Procedure<? super V> procedure)
Multimap
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" ]
forEachValue
in interface Multimap<K,V>
public void forEachKey(Procedure<? super K> procedure)
Multimap
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" ]
forEachKey
in interface Multimap<K,V>
public void forEachKeyValue(Procedure2<K,V> procedure)
Multimap
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"] ]
forEachKeyValue
in interface Multimap<K,V>
public void forEachKeyMultiValues(Procedure2<K,? super Iterable<V>> procedure)
Multimap
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"]}] ]
forEachKeyMultiValues
in interface Multimap<K,V>
public <R extends MutableMultimap<K,V>> R selectKeysValues(Predicate2<? super K,? super V> predicate, R target)
Multimap
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());
selectKeysValues
in interface Multimap<K,V>
predicate
- a Predicate2
to use as the select criteriatarget
- the Multimap to append to for all elements in this Multimap
that satisfy the predicate
target
, which contains appended elements as a result of the select criteriapublic <R extends MutableMultimap<K,V>> R rejectKeysValues(Predicate2<? super K,? super V> predicate, R target)
Multimap
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());
rejectKeysValues
in interface Multimap<K,V>
predicate
- a Predicate2
to use as the reject criteriatarget
- the Multimap to append to for all elements in this Multimap
that don't satisfy the predicate
target
, which contains appended elements that don't satisfy the predicate
public <R extends MutableMultimap<K,V>> R selectKeysMultiValues(Predicate2<? super K,? super Iterable<V>> predicate, R target)
Multimap
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());
selectKeysMultiValues
in interface Multimap<K,V>
predicate
- a Predicate2
to use as the select criteriatarget
- the Multimap to append to for all elements in this Multimap
that satisfy the predicate
target
, which contains appended elements as a result of the select criteriapublic <R extends MutableMultimap<K,V>> R rejectKeysMultiValues(Predicate2<? super K,? super Iterable<V>> predicate, R target)
Multimap
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());
rejectKeysMultiValues
in interface Multimap<K,V>
predicate
- a Predicate2
to use as the reject criteriatarget
- the Multimap to append to for all elements in this Multimap
that don't satisfy the predicate
target
, which contains appended elements that don't satisfy the predicate
public <K2,V2,R extends MutableMultimap<K2,V2>> R collectKeysValues(Function2<? super K,? super V,Pair<K2,V2>> function, R target)
Multimap
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.newMultimap());
collectKeysValues
in interface Multimap<K,V>
function
- a Function2
to use for transformationtarget
- the Multimap to append for all elements in this Multimap
that are evaluated in function
target
, which contains appended elements as a result of the transformationpublic <V2,R extends MutableMultimap<K,V2>> R collectValues(Function<? super V,? extends V2> function, R target)
Multimap
e.g. return multimap.collectValues(new Function<Person, String>() { public String valueOf(Person person) { return person.getLastName(); } }, FastListMultimap.newMultimap());
collectValues
in interface Multimap<K,V>
function
- a Function
to use for transformationtarget
- the Multimap to append for all elements in this Multimap
that are evaluated in function
target
, which contains appended elements as a result of the transformationCopyright © 2004–2016. All rights reserved.