Multimap<K,V>
, MutableMultimap<K,V>
SynchronizedBagMultimap
, SynchronizedListMultimap
, SynchronizedSetMultimap
, SynchronizedSortedBagMultimap
, SynchronizedSortedSetMultimap
public abstract class AbstractSynchronizedMultimap<K,V> extends java.lang.Object implements MutableMultimap<K,V>
Modifier and Type | Method | Description |
---|---|---|
boolean |
add(Pair<K,V> keyValuePair) |
Modification operation similar to put, however, takes the key-value pair as the input.
|
void |
clear() |
|
<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(java.lang.Object key) |
Returns
true if any values are mapped to the specified key. |
boolean |
containsKeyAndValue(java.lang.Object key,
java.lang.Object value) |
Returns
true if the specified key-value pair is mapped. |
boolean |
containsValue(java.lang.Object value) |
Returns
true if any key is mapped to the specified value. |
boolean |
equals(java.lang.Object obj) |
Compares the specified object with this Multimap for equality.
|
void |
forEachKey(Procedure<? super K> procedure) |
Calls the
procedure with each key. |
void |
forEachKeyMultiValues(Procedure2<? super K,? super java.lang.Iterable<V>> procedure) |
Calls the
procedure with each key-Iterable[value]. |
void |
forEachKeyValue(Procedure2<? super K,? super 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.
|
boolean |
isEmpty() |
Returns
true if there are no entries. |
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.
|
SetIterable<K> |
keySet() |
Returns a unmodifiable
SetIterable of keys with O(1) complexity. |
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. |
boolean |
put(K key,
V value) |
|
boolean |
putAll(K key,
java.lang.Iterable<? extends V> values) |
|
<KK extends K,VV extends V> |
putAll(Multimap<KK,VV> multimap) |
|
boolean |
putAllPairs(java.lang.Iterable<Pair<K,V>> pairs) |
|
boolean |
putAllPairs(Pair<K,V>... pairs) |
|
<R extends MutableMultimap<K,V>> |
rejectKeysMultiValues(Predicate2<? super K,? super java.lang.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.
|
boolean |
remove(java.lang.Object key,
java.lang.Object value) |
|
<R extends MutableMultimap<K,V>> |
selectKeysMultiValues(Predicate2<? super K,? super java.lang.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.
|
int |
size() |
Returns the number of key-value entry pairs.
|
int |
sizeDistinct() |
Returns the number of distinct keys.
|
MutableMap<K,RichIterable<V>> |
toMap() |
Returns a new
MutableMap of keys from this Multimap to the mapped values as a RichIterable . |
<R extends java.util.Collection<V>> |
toMap(Function0<R> collectionFactory) |
Returns a new
MutableMap of keys from this Multimap to the mapped values as a RichIterable . |
java.lang.String |
toString() |
|
RichIterable<V> |
valuesView() |
Returns a lazy flattened view of all the values.
|
toImmutable, toMutable
asSynchronized, collectKeysValues, collectValues, flip, get, newEmpty, rejectKeysMultiValues, rejectKeysValues, removeAll, replaceValues, selectKeysMultiValues, selectKeysValues
public boolean equals(java.lang.Object obj)
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()
Multimap
The hash code of a Multimap is defined as the hash code of the map view, as returned by Multimap.toMap()
.
public java.lang.String toString()
toString
in class java.lang.Object
public boolean add(Pair<K,V> keyValuePair)
MutableMultimap
add
in interface MutableMultimap<K,V>
keyValuePair
- key value pair to add in the multimapMutableMultimap.put(Object, Object)
public boolean remove(java.lang.Object key, java.lang.Object value)
remove
in interface MutableMultimap<K,V>
public boolean putAllPairs(Pair<K,V>... pairs)
putAllPairs
in interface MutableMultimap<K,V>
public boolean putAllPairs(java.lang.Iterable<Pair<K,V>> pairs)
putAllPairs
in interface MutableMultimap<K,V>
public boolean putAll(K key, java.lang.Iterable<? extends V> values)
putAll
in interface MutableMultimap<K,V>
public <KK extends K,VV extends V> boolean putAll(Multimap<KK,VV> multimap)
putAll
in interface MutableMultimap<K,V>
public void clear()
clear
in interface MutableMultimap<K,V>
public boolean isEmpty()
Multimap
true
if there are no entries.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<? super K,? super 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<? super K,? super java.lang.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 int size()
Multimap
This method is implemented with O(1) (constant-time) performance.
public int sizeDistinct()
Multimap
sizeDistinct
in interface Multimap<K,V>
public boolean containsKey(java.lang.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(java.lang.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(java.lang.Object key, java.lang.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 SetIterable<K> keySet()
Multimap
SetIterable
of keys with O(1) complexity.public Bag<K> keyBag()
Multimap
Bag
of keys with the count corresponding to the number of mapped values.public RichIterable<RichIterable<V>> multiValuesView()
Multimap
multiValuesView
in interface Multimap<K,V>
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 MutableMap<K,RichIterable<V>> toMap()
Multimap
MutableMap
of keys from this Multimap to the mapped values as a RichIterable
.public <R extends java.util.Collection<V>> MutableMap<K,R> toMap(Function0<R> collectionFactory)
Multimap
MutableMap
of keys from this Multimap to the mapped values as a RichIterable
.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 java.lang.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 java.lang.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.<String, String>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.<Integer, String>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–2017. All rights reserved.