Class AbstractSynchronizedMultimap<K,V>
- java.lang.Object
-
- org.eclipse.collections.impl.multimap.AbstractSynchronizedMultimap<K,V>
-
- All Implemented Interfaces:
Multimap<K,V>,MutableMultimap<K,V>
- Direct Known Subclasses:
SynchronizedBagMultimap,SynchronizedListMultimap,SynchronizedSetMultimap,SynchronizedSortedBagMultimap,SynchronizedSortedSetMultimap
public abstract class AbstractSynchronizedMultimap<K,V> extends java.lang.Object implements MutableMultimap<K,V>
-
-
Field Summary
Fields Modifier and Type Field Description protected MutableMultimap<K,V>delegateprivate java.lang.Objectlock
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractSynchronizedMultimap(MutableMultimap<K,V> multimap)protectedAbstractSynchronizedMultimap(MutableMultimap<K,V> multimap, java.lang.Object newLock)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(Pair<? extends K,? extends V> keyValuePair)Modification 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(java.lang.Object key)Returnstrueif any values are mapped to the specified key.booleancontainsKeyAndValue(java.lang.Object key, java.lang.Object value)Returnstrueif the specified key-value pair is mapped.booleancontainsValue(java.lang.Object value)Returnstrueif any key is mapped to the specified value.booleanequals(java.lang.Object obj)Compares 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>getDelegate()protected java.lang.ObjectgetLock()inthashCode()Returns the hash code for this Multimap.booleanisEmpty()Returnstrueif there are no entries.Bag<K>keyBag()Returns aBagof 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 a lazy view of the values mapped to that key.SetIterable<K>keySet()Returns an unmodifiableSetIterableof 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 the key/value pairs.RichIterable<RichIterable<V>>multiValuesView()Returns an unmodifiable view of all the values mapped to each key.booleannotEmpty()Returnstrueif there is at least one entry.booleanput(K key, V value)booleanputAll(K key, java.lang.Iterable<? extends V> values)<KK extends K,VV extends V>
booleanputAll(Multimap<KK,VV> multimap)booleanputAllPairs(java.lang.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.booleanremove(java.lang.Object key, java.lang.Object value)<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.intsizeDistinct()Returns 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 java.util.Collection<V>>
MutableMap<K,R>toMap(Function0<R> collectionFactory)Returns a newMutableMapof keys from this Multimap to the mapped values as aRichIterable.java.lang.StringtoString()RichIterable<V>valuesView()Returns a lazy flattened view of all the values.MutableMultimap<K,V>withKeyMultiValues(K key, V... values)Puts the key / values combination into the MutableMultimap and returns the MutableMultimap (this).protected java.lang.ObjectwriteReplace()-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface org.eclipse.collections.api.multimap.Multimap
toImmutable, toMutable
-
Methods inherited from interface org.eclipse.collections.api.multimap.MutableMultimap
asSynchronized, collectKeyMultiValues, collectKeysValues, collectValues, flip, get, getIfAbsentPutAll, newEmpty, rejectKeysMultiValues, rejectKeysValues, removeAll, replaceValues, selectKeysMultiValues, selectKeysValues, withKeyValue
-
-
-
-
Field Detail
-
delegate
protected final MutableMultimap<K,V> delegate
-
lock
private final java.lang.Object lock
-
-
Constructor Detail
-
AbstractSynchronizedMultimap
protected AbstractSynchronizedMultimap(MutableMultimap<K,V> multimap, java.lang.Object newLock)
-
AbstractSynchronizedMultimap
protected AbstractSynchronizedMultimap(MutableMultimap<K,V> multimap)
-
-
Method Detail
-
getDelegate
protected MutableMultimap<K,V> getDelegate()
-
getLock
protected java.lang.Object getLock()
-
writeReplace
protected java.lang.Object writeReplace()
-
equals
public boolean equals(java.lang.Object obj)
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
public int hashCode()
Description copied from interface:MultimapReturns 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
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
add
public boolean add(Pair<? extends K,? extends V> keyValuePair)
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:
MutableMultimap.put(Object, Object)
-
remove
public boolean remove(java.lang.Object key, java.lang.Object value)- Specified by:
removein interfaceMutableMultimap<K,V>
-
withKeyMultiValues
public MutableMultimap<K,V> withKeyMultiValues(K key, V... values)
Description copied from interface:MutableMultimapPuts the key / values combination into the MutableMultimap and returns the MutableMultimap (this).- Specified by:
withKeyMultiValuesin interfaceMutableMultimap<K,V>
-
putAllPairs
public boolean putAllPairs(Pair<? extends K,? extends V>... pairs)
- Specified by:
putAllPairsin interfaceMutableMultimap<K,V>
-
putAllPairs
public boolean putAllPairs(java.lang.Iterable<? extends Pair<? extends K,? extends V>> pairs)
- Specified by:
putAllPairsin interfaceMutableMultimap<K,V>
-
putAll
public boolean putAll(K key, java.lang.Iterable<? extends V> values)
- Specified by:
putAllin interfaceMutableMultimap<K,V>
-
putAll
public <KK extends K,VV extends V> boolean putAll(Multimap<KK,VV> multimap)
- Specified by:
putAllin interfaceMutableMultimap<K,V>
-
clear
public void clear()
- Specified by:
clearin interfaceMutableMultimap<K,V>
-
isEmpty
public boolean isEmpty()
Description copied from interface:MultimapReturnstrueif there are no entries.
-
notEmpty
public boolean notEmpty()
Description copied from interface:MultimapReturnstrueif there is at least one entry.
-
forEachValue
public void forEachValue(Procedure<? super V> procedure)
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
public void forEachKey(Procedure<? super K> procedure)
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
public void forEachKeyValue(Procedure2<? super K,? super V> procedure)
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
public void forEachKeyMultiValues(Procedure2<? super K,? super RichIterable<V>> procedure)
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
public int size()
Description copied from interface:MultimapReturns the number of key-value entry pairs.This method is implemented with O(1) (constant-time) performance.
-
sizeDistinct
public int sizeDistinct()
Description copied from interface:MultimapReturns the number of distinct keys.- Specified by:
sizeDistinctin interfaceMultimap<K,V>
-
containsKey
public boolean containsKey(java.lang.Object key)
Description copied from interface:MultimapReturnstrueif any values are mapped to the specified key.- Specified by:
containsKeyin interfaceMultimap<K,V>- Parameters:
key- the key to search for
-
containsValue
public boolean containsValue(java.lang.Object value)
Description copied from interface:MultimapReturnstrueif any key is mapped to the specified value.- Specified by:
containsValuein interfaceMultimap<K,V>- Parameters:
value- the value to search for
-
containsKeyAndValue
public boolean containsKeyAndValue(java.lang.Object key, java.lang.Object value)Description copied from interface:MultimapReturnstrueif the specified key-value pair is mapped.- Specified by:
containsKeyAndValuein interfaceMultimap<K,V>- Parameters:
key- the key to search forvalue- the value to search for
-
keysView
public RichIterable<K> keysView()
Description copied from interface:MultimapReturns a lazy view of the unique keys.
-
keySet
public SetIterable<K> keySet()
Description copied from interface:MultimapReturns an unmodifiableSetIterableof keys with O(1) complexity.
-
keyBag
public Bag<K> keyBag()
Description copied from interface:MultimapReturns aBagof keys with the count corresponding to the number of mapped values.
-
multiValuesView
public RichIterable<RichIterable<V>> multiValuesView()
Description copied from interface:MultimapReturns an unmodifiable view of all the values mapped to each key.- Specified by:
multiValuesViewin interfaceMultimap<K,V>
-
valuesView
public RichIterable<V> valuesView()
Description copied from interface:MultimapReturns a lazy flattened view of all the values.- Specified by:
valuesViewin interfaceMultimap<K,V>
-
keyMultiValuePairsView
public RichIterable<Pair<K,RichIterable<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
public RichIterable<Pair<K,V>> keyValuePairsView()
Description copied from interface:MultimapReturns a lazy view of all the key/value pairs.- Specified by:
keyValuePairsViewin interfaceMultimap<K,V>
-
toMap
public MutableMap<K,RichIterable<V>> toMap()
Description copied from interface:MultimapReturns a newMutableMapof keys from this Multimap to the mapped values as aRichIterable.
-
toMap
public <R extends java.util.Collection<V>> MutableMap<K,R> toMap(Function0<R> collectionFactory)
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
-
-