Class AbstractMultimap<K, V, C extends RichIterable<V>>
- All Implemented Interfaces:
Multimap<K,V>
- Direct Known Subclasses:
AbstractImmutableMultimap, AbstractMutableMultimap
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final class -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescription<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.booleancontainsKey(Object key) Returnstrueif any values are mapped to the specified key.booleancontainsKeyAndValue(Object key, Object value) Returnstrueif the specified key-value pair is mapped.booleancontainsValue(Object value) Returnstrueif any key is mapped to the specified value.protected abstract CCreates the collection of values for a single key.booleanCompares the specified object with this Multimap for equality.voidforEachKey(Procedure<? super K> procedure) Calls theprocedurewith each key.voidforEachKeyMultiValues(Procedure2<? super K, ? super RichIterable<V>> procedure) Calls theprocedurewith each key-Iterable[value].voidforEachKeyValue(Procedure2<? super K, ? super V> procedure) Calls theprocedurewith each key-value pair.voidforEachValue(Procedure<? super V> procedure) Calls the procedure with each value.protected abstract MapIterable<K, C> getMap()inthashCode()Returns the hash code for this multimap.keyBag()Returns aBagof keys with the count corresponding to the number of mapped values.RichIterable<Pair<K, RichIterable<V>>> Returns a lazy view of the pair of a key and a lazy view of the values mapped to that key.keysView()Returns a lazy view of the unique keys.RichIterable<Pair<K, V>> Returns a lazy view of all the key/value pairs.Returns an unmodifiable view of all the values mapped to each key.booleannotEmpty()Returnstrueif there is at least one entry.<R extends MutableMultimap<K,V>>
RrejectKeysMultiValues(Predicate2<? super K, ? super RichIterable<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 RichIterable<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.toString()Returns a string representation of the multimap, generated by callingtoStringon the map returned byMultimap.toMap().Returns a lazy flattened view of all the values.Methods inherited from interface 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
-
getMap
-
createCollection
Creates the collection of values for a single key.Collections with weak, soft, or phantom references are not supported. Each call to
createCollectionshould create a new instance.The returned collection class determines whether duplicate key-value pairs are allowed.
- Returns:
- an empty collection of values
-
createCollectionBlock
-
containsKey
-
containsValue
-
containsKeyAndValue
-
keysView
-
multiValuesView
Description copied from interface:MultimapReturns an unmodifiable view of all the values mapped to each key.- Specified by:
multiValuesViewin interfaceMultimap<K,V>
-
keyBag
-
valuesView
Description copied from interface:MultimapReturns a lazy flattened view of all the values.- Specified by:
valuesViewin interfaceMultimap<K,V>
-
keyMultiValuePairsView
Description copied from interface:MultimapReturns a lazy view of the pair of a key and a lazy view of the values mapped to that key.- Specified by:
keyMultiValuePairsViewin interfaceMultimap<K,V>
-
keyValuePairsView
Description copied from interface:MultimapReturns a lazy view of all the key/value pairs.- Specified by:
keyValuePairsViewin interfaceMultimap<K,V>
-
equals
Description copied from interface:MultimapCompares 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
-
toString
Returns a string representation of the multimap, generated by callingtoStringon the map returned byMultimap.toMap(). -
notEmpty
-
forEachValue
Description copied from interface:MultimapCalls the procedure with each value.Given a Multimap with the contents:
The given procedure would be invoked with the parameters:{"key1" : ["val1", "val2", "val2"], "key2" : ["val3"]}["val1", "val2", "val2", "val3"]- Specified by:
forEachValuein interfaceMultimap<K,V>
-
forEachKey
Description copied from interface:MultimapCalls theprocedurewith 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:
forEachKeyin interfaceMultimap<K,V>
-
forEachKeyValue
Description copied from interface:MultimapCalls theprocedurewith 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:
forEachKeyValuein interfaceMultimap<K,V>
-
forEachKeyMultiValues
Description copied from interface:MultimapCalls theprocedurewith 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:
forEachKeyMultiValuesin interfaceMultimap<K,V>
-
selectKeysValues
public <R extends MutableMultimap<K,V>> R selectKeysValues(Predicate2<? super K, ? super V> predicate, R target) Description copied from interface:MultimapSame 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:
selectKeysValuesin interfaceMultimap<K,V> - Parameters:
predicate- aPredicate2to use as the select criteriatarget- the Multimap to append to for all elements in thisMultimapthat 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:MultimapSame 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:
rejectKeysValuesin interfaceMultimap<K,V> - Parameters:
predicate- aPredicate2to use as the reject criteriatarget- the Multimap to append to for all elements in thisMultimapthat 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 RichIterable<V>> predicate, R target) Description copied from interface:MultimapSame 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:
selectKeysMultiValuesin interfaceMultimap<K,V> - Parameters:
predicate- aPredicate2to use as the select criteriatarget- the Multimap to append to for all elements in thisMultimapthat 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 RichIterable<V>> predicate, R target) Description copied from interface:MultimapSame 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:
rejectKeysMultiValuesin interfaceMultimap<K,V> - Parameters:
predicate- aPredicate2to use as the reject criteriatarget- the Multimap to append to for all elements in thisMultimapthat 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:MultimapSame 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:
collectKeysValuesin interfaceMultimap<K,V> - Parameters:
function- aFunction2to use for transformationtarget- the Multimap to append for all elements in thisMultimapthat 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:MultimapSame 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:
collectKeyMultiValuesin interfaceMultimap<K,V> - Parameters:
keyFunction-Functionto use transformation to get the keyvalueFunction-Functionto use transformation to get the valuestarget- the Multimap to append for all elements in thisMultimapthat are evaluated inkeyFunctionandvalueFunction- 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:MultimapSame 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:
collectValuesin interfaceMultimap<K,V> - Parameters:
function- aFunctionto use for transformationtarget- the Multimap to append for all elements in thisMultimapthat are evaluated infunction- Returns:
target, which contains appended elements as a result of the transformation
-