Class AbstractSynchronizedMultimap<K,V>
- All Implemented Interfaces:
Multimap<K,V>, MutableMultimap<K, V>
- Direct Known Subclasses:
SynchronizedBagMultimap, SynchronizedListMultimap, SynchronizedSetMultimap, SynchronizedSortedBagMultimap, SynchronizedSortedSetMultimap
-
Field Summary
Fields -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractSynchronizedMultimap(MutableMultimap<K, V> multimap) protectedAbstractSynchronizedMultimap(MutableMultimap<K, V> multimap, Object newLock) -
Method Summary
Modifier and TypeMethodDescriptionbooleanModification operation similar to put, however, takes the key-value pair as the input.voidclear()<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.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 MutableMultimap<K, V> protected ObjectgetLock()inthashCode()Returns the hash code for this Multimap.booleanisEmpty()Returnstrueif there are no entries.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.keySet()Returns an unmodifiableSetIterableof keys with O(1) complexity.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.booleanbooleanbooleanputAllPairs(Iterable<? extends Pair<? extends K, ? extends V>> pairs) booleanputAllPairs(Pair<? extends K, ? extends V>... pairs) <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.boolean<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.intsize()Returns the number of key-value entry pairs.intReturns the number of distinct keys.MutableMap<K, RichIterable<V>> toMap()Returns a newMutableMapof keys from this Multimap to the mapped values as aRichIterable.<R extends Collection<V>>
MutableMap<K, R> Returns a newMutableMapof keys from this Multimap to the mapped values as aRichIterable.toString()Returns a lazy flattened view of all the values.withKeyMultiValues(K key, V... values) Puts the key / values combination into the MutableMultimap and returns the MutableMultimap (this).protected ObjectMethods inherited from interface Multimap
toImmutable, toMutableMethods inherited from interface MutableMultimap
asSynchronized, collectKeyMultiValues, collectKeysValues, collectValues, flip, get, getIfAbsentPutAll, newEmpty, rejectKeysMultiValues, rejectKeysValues, removeAll, replaceValues, selectKeysMultiValues, selectKeysValues, withKeyValue
-
Field Details
-
delegate
-
lock
-
-
Constructor Details
-
AbstractSynchronizedMultimap
-
AbstractSynchronizedMultimap
-
-
Method Details
-
getDelegate
-
getLock
-
writeReplace
-
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
-
put
-
add
Description copied from interface:MutableMultimapModification operation similar to put, however, takes the key-value pair as the input.- Specified by:
addin interfaceMutableMultimap<K,V> - Parameters:
keyValuePair- key value pair to add in the multimap- See Also:
-
remove
-
withKeyMultiValues
Description copied from interface:MutableMultimapPuts the key / values combination into the MutableMultimap and returns the MutableMultimap (this).- Specified by:
withKeyMultiValuesin interfaceMutableMultimap<K,V>
-
putAllPairs
- Specified by:
putAllPairsin interfaceMutableMultimap<K,V>
-
putAllPairs
- Specified by:
putAllPairsin interfaceMutableMultimap<K,V>
-
putAll
-
putAll
-
clear
public void clear()- Specified by:
clearin interfaceMutableMultimap<K,V>
-
isEmpty
-
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>
-
size
-
sizeDistinct
public int sizeDistinct()Description copied from interface:MultimapReturns the number of distinct keys.- Specified by:
sizeDistinctin interfaceMultimap<K,V>
-
containsKey
-
containsValue
-
containsKeyAndValue
-
keysView
-
keySet
Description copied from interface:MultimapReturns an unmodifiableSetIterableof keys with O(1) complexity. -
keyBag
-
multiValuesView
Description copied from interface:MultimapReturns an unmodifiable view of all the values mapped to each key.- Specified by:
multiValuesViewin interfaceMultimap<K,V>
-
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>
-
toMap
Description copied from interface:MultimapReturns a newMutableMapof keys from this Multimap to the mapped values as aRichIterable. -
toMap
Description copied from interface:MultimapReturns a newMutableMapof keys from this Multimap to the mapped values as aRichIterable. -
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
-