Class SynchronizedBagMultimap<K,V>
java.lang.Object
org.eclipse.collections.impl.multimap.AbstractSynchronizedMultimap<K,V>
org.eclipse.collections.impl.multimap.bag.SynchronizedBagMultimap<K,V>
- All Implemented Interfaces:
Serializable
,BagMultimap<K,V>
,MutableBagIterableMultimap<K,V>
,MutableBagMultimap<K,V>
,UnsortedBagMultimap<K,V>
,Multimap<K,V>
,MutableMultimap<K,V>
public class SynchronizedBagMultimap<K,V> extends AbstractSynchronizedMultimap<K,V> implements MutableBagMultimap<K,V>, Serializable
- See Also:
- Serialized Form
-
Constructor Summary
Constructors Constructor Description SynchronizedBagMultimap(MutableBagMultimap<K,V> multimap)
SynchronizedBagMultimap(MutableBagMultimap<K,V> multimap, Object newLock)
-
Method Summary
Modifier and Type Method Description MutableBagMultimap<K,V>
asSynchronized()
Returns a synchronized wrapper backed by this multimap.<K2, V2> MutableBagMultimap<K2,V2>
collectKeyMultiValues(Function<? super K,? extends K2> keyFunction, Function<? super V,? extends V2> valueFunction)
Returns a new multimap with the results of applying the specified keyFunction and valueFunction on each key and corresponding values of the source multimap.<K2, V2> MutableBagMultimap<K2,V2>
collectKeysValues(Function2<? super K,? super V,Pair<K2,V2>> function)
Returns a new multimap with the results of applying the specified function on each key and value of the source multimap.<V2> MutableBagMultimap<K,V2>
collectValues(Function<? super V,? extends V2> function)
Returns a new multimap with the results of applying the specified function on each value of the source multimap.MutableBagMultimap<V,K>
flip()
Given a Multimap from Domain->
Range return a multimap from Range->
Domain.MutableBag<V>
get(K key)
Returns a view of all values associated with the given key.MutableBag<V>
getIfAbsentPutAll(K key, Iterable<? extends V> values)
Puts values into multimap if there are no values already associated with key.MutableBagMultimap<K,V>
newEmpty()
Creates a new instance of the same implementation type, using the default capacity and growth parameters.static <K, V> SynchronizedBagMultimap<K,V>
of(MutableBagMultimap<K,V> multimap)
This method will take a Multimap and wrap it directly in a SynchronizedBagMultimap.static <K, V> SynchronizedBagMultimap<K,V>
of(MutableBagMultimap<K,V> multimap, Object lock)
This method will take a Multimap and wrap it directly in a SynchronizedBagMultimap.void
putOccurrences(K key, V value, int occurrences)
MutableBagMultimap<K,V>
rejectKeysMultiValues(Predicate2<? super K,? super Iterable<V>> predicate)
Returns all elements of the source multimap that don't satisfy the predicate.MutableBagMultimap<K,V>
rejectKeysValues(Predicate2<? super K,? super V> predicate)
Returns all elements of the source multimap that don't satisfy the predicate.MutableBag<V>
removeAll(Object key)
MutableBag<V>
replaceValues(K key, Iterable<? extends V> values)
MutableBagMultimap<K,V>
selectKeysMultiValues(Predicate2<? super K,? super Iterable<V>> predicate)
Returns all elements of the source multimap that satisfies the predicate.MutableBagMultimap<K,V>
selectKeysValues(Predicate2<? super K,? super V> predicate)
Returns all elements of the source multimap that satisfies the predicate.ImmutableBagMultimap<K,V>
toImmutable()
Returns an immutable copy of this Multimap if it is not already immutable.MutableBagMultimap<K,V>
toMutable()
Returns a mutable copy of this Multimap.Methods inherited from class org.eclipse.collections.impl.multimap.AbstractSynchronizedMultimap
add, clear, collectKeyMultiValues, collectKeysValues, collectValues, containsKey, containsKeyAndValue, containsValue, equals, forEachKey, forEachKeyMultiValues, forEachKeyValue, forEachValue, hashCode, isEmpty, keyBag, keyMultiValuePairsView, keySet, keysView, keyValuePairsView, multiValuesView, notEmpty, put, putAll, putAll, putAllPairs, putAllPairs, rejectKeysMultiValues, rejectKeysValues, remove, selectKeysMultiValues, selectKeysValues, size, sizeDistinct, toMap, toMap, toString, valuesView
Methods inherited from interface org.eclipse.collections.api.multimap.Multimap
collectKeyMultiValues, collectKeysValues, collectValues, containsKey, containsKeyAndValue, containsValue, equals, forEachKey, forEachKeyMultiValues, forEachKeyValue, forEachValue, hashCode, isEmpty, keyBag, keyMultiValuePairsView, keySet, keysView, keyValuePairsView, multiValuesView, notEmpty, rejectKeysMultiValues, rejectKeysValues, selectKeysMultiValues, selectKeysValues, size, sizeDistinct, toMap, toMap, valuesView
Methods inherited from interface org.eclipse.collections.api.multimap.MutableMultimap
add, clear, put, putAll, putAll, putAllPairs, putAllPairs, remove
-
Constructor Details
-
Method Details
-
of
This method will take a Multimap and wrap it directly in a SynchronizedBagMultimap. -
of
public static <K, V> SynchronizedBagMultimap<K,V> of(MutableBagMultimap<K,V> multimap, Object lock)This method will take a Multimap and wrap it directly in a SynchronizedBagMultimap. Additionally, a developer specifies which lock to use with the collection. -
replaceValues
- Specified by:
replaceValues
in interfaceMutableBagIterableMultimap<K,V>
- Specified by:
replaceValues
in interfaceMutableBagMultimap<K,V>
- Specified by:
replaceValues
in interfaceMutableMultimap<K,V>
-
removeAll
- Specified by:
removeAll
in interfaceMutableBagIterableMultimap<K,V>
- Specified by:
removeAll
in interfaceMutableBagMultimap<K,V>
- Specified by:
removeAll
in interfaceMutableMultimap<K,V>
-
newEmpty
Description copied from interface:Multimap
Creates a new instance of the same implementation type, using the default capacity and growth parameters.- Specified by:
newEmpty
in interfaceBagMultimap<K,V>
- Specified by:
newEmpty
in interfaceMultimap<K,V>
- Specified by:
newEmpty
in interfaceMutableBagIterableMultimap<K,V>
- Specified by:
newEmpty
in interfaceMutableBagMultimap<K,V>
- Specified by:
newEmpty
in interfaceMutableMultimap<K,V>
- Specified by:
newEmpty
in interfaceUnsortedBagMultimap<K,V>
-
get
Description copied from interface:Multimap
Returns a view of all values associated with the given key.If the given key does not exist, an empty
RichIterable
is returned.- Specified by:
get
in interfaceBagMultimap<K,V>
- Specified by:
get
in interfaceMultimap<K,V>
- Specified by:
get
in interfaceMutableBagIterableMultimap<K,V>
- Specified by:
get
in interfaceMutableBagMultimap<K,V>
- Specified by:
get
in interfaceMutableMultimap<K,V>
- Specified by:
get
in interfaceUnsortedBagMultimap<K,V>
- Parameters:
key
- the key to search for
-
getIfAbsentPutAll
Description copied from interface:MutableMultimap
Puts values into multimap if there are no values already associated with key. Then returns a view of the values associated with key, like the result ofMultimap.get(Object)
- Specified by:
getIfAbsentPutAll
in interfaceMutableBagIterableMultimap<K,V>
- Specified by:
getIfAbsentPutAll
in interfaceMutableBagMultimap<K,V>
- Specified by:
getIfAbsentPutAll
in interfaceMutableMultimap<K,V>
-
toMutable
Description copied from interface:Multimap
Returns a mutable copy of this Multimap. -
toImmutable
Description copied from interface:Multimap
Returns an immutable copy of this Multimap if it is not already immutable. If the Multimap is immutable, it will return itself.The returned Multimap will be
Serializable
if this Multimap isSerializable
.- Specified by:
toImmutable
in interfaceMultimap<K,V>
- Specified by:
toImmutable
in interfaceUnsortedBagMultimap<K,V>
-
putOccurrences
- Specified by:
putOccurrences
in interfaceMutableBagMultimap<K,V>
-
flip
Description copied from interface:Multimap
Given a Multimap from Domain->
Range return a multimap from Range->
Domain.- Specified by:
flip
in interfaceBagMultimap<K,V>
- Specified by:
flip
in interfaceMultimap<K,V>
- Specified by:
flip
in interfaceMutableBagIterableMultimap<K,V>
- Specified by:
flip
in interfaceMutableBagMultimap<K,V>
- Specified by:
flip
in interfaceMutableMultimap<K,V>
-
selectKeysValues
Description copied from interface:Multimap
Returns all elements of the source multimap that satisfies the predicate. This method is also commonly called filter.e.g. return multimap.selectKeysValues(new Predicate2<Integer, Person>() { public boolean accept(Integer age, Person person) { return (age >= 18) && (person.getAddress().getCity().equals("Metuchen")); } });
- Specified by:
selectKeysValues
in interfaceBagMultimap<K,V>
- Specified by:
selectKeysValues
in interfaceMultimap<K,V>
- Specified by:
selectKeysValues
in interfaceMutableBagIterableMultimap<K,V>
- Specified by:
selectKeysValues
in interfaceMutableBagMultimap<K,V>
- Specified by:
selectKeysValues
in interfaceMutableMultimap<K,V>
- Specified by:
selectKeysValues
in interfaceUnsortedBagMultimap<K,V>
- Parameters:
predicate
- aPredicate2
to use as the select criteria- Returns:
Multimap
, which contains elements as a result of the select criteria
-
rejectKeysValues
Description copied from interface:Multimap
Returns all elements of the source multimap that don't satisfy the predicate.e.g. return multimap.rejectKeysValues(new Predicate2<Integer, Person>() { public boolean accept(Integer age, Person person) { return (age >= 18) && (person.getAddress().getCity().equals("Metuchen")); } });
- Specified by:
rejectKeysValues
in interfaceBagMultimap<K,V>
- Specified by:
rejectKeysValues
in interfaceMultimap<K,V>
- Specified by:
rejectKeysValues
in interfaceMutableBagIterableMultimap<K,V>
- Specified by:
rejectKeysValues
in interfaceMutableBagMultimap<K,V>
- Specified by:
rejectKeysValues
in interfaceMutableMultimap<K,V>
- Specified by:
rejectKeysValues
in interfaceUnsortedBagMultimap<K,V>
- Parameters:
predicate
- aPredicate2
to use as the reject criteria- Returns:
Multimap
, which contains elements that don't satisfy thepredicate
-
selectKeysMultiValues
public MutableBagMultimap<K,V> selectKeysMultiValues(Predicate2<? super K,? super Iterable<V>> predicate)Description copied from interface:Multimap
Returns all elements of the source multimap that satisfies the predicate. This method is also commonly called filter.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); } });
- Specified by:
selectKeysMultiValues
in interfaceBagMultimap<K,V>
- Specified by:
selectKeysMultiValues
in interfaceMultimap<K,V>
- Specified by:
selectKeysMultiValues
in interfaceMutableBagIterableMultimap<K,V>
- Specified by:
selectKeysMultiValues
in interfaceMutableBagMultimap<K,V>
- Specified by:
selectKeysMultiValues
in interfaceMutableMultimap<K,V>
- Specified by:
selectKeysMultiValues
in interfaceUnsortedBagMultimap<K,V>
- Parameters:
predicate
- aPredicate2
to use as the select criteria- Returns:
Multimap
, which contains elements as a result of the select criteria
-
rejectKeysMultiValues
public MutableBagMultimap<K,V> rejectKeysMultiValues(Predicate2<? super K,? super Iterable<V>> predicate)Description copied from interface:Multimap
Returns all elements of the source multimap that don't satisfy the predicate.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); } });
- Specified by:
rejectKeysMultiValues
in interfaceBagMultimap<K,V>
- Specified by:
rejectKeysMultiValues
in interfaceMultimap<K,V>
- Specified by:
rejectKeysMultiValues
in interfaceMutableBagIterableMultimap<K,V>
- Specified by:
rejectKeysMultiValues
in interfaceMutableBagMultimap<K,V>
- Specified by:
rejectKeysMultiValues
in interfaceMutableMultimap<K,V>
- Specified by:
rejectKeysMultiValues
in interfaceUnsortedBagMultimap<K,V>
- Parameters:
predicate
- aPredicate2
to use as the reject criteria- Returns:
Multimap
, which contains elements that don't satisfy thepredicate
-
collectKeysValues
public <K2, V2> MutableBagMultimap<K2,V2> collectKeysValues(Function2<? super K,? super V,Pair<K2,V2>> function)Description copied from interface:Multimap
Returns a new multimap with the results of applying the specified function on each key and value of the source multimap. This method is also commonly called transform or map.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()); } });
- Specified by:
collectKeysValues
in interfaceMultimap<K,V>
- Specified by:
collectKeysValues
in interfaceMutableBagIterableMultimap<K,V>
- Specified by:
collectKeysValues
in interfaceMutableBagMultimap<K,V>
- Specified by:
collectKeysValues
in interfaceMutableMultimap<K,V>
- Specified by:
collectKeysValues
in interfaceUnsortedBagMultimap<K,V>
- Parameters:
function
- aFunction2
to use for transformation- Returns:
Multimap
, which contains elements as a result of the transformation
-
collectKeyMultiValues
public <K2, V2> MutableBagMultimap<K2,V2> collectKeyMultiValues(Function<? super K,? extends K2> keyFunction, Function<? super V,? extends V2> valueFunction)Description copied from interface:Multimap
Returns a new multimap with the results of applying the specified keyFunction and valueFunction on each key and corresponding values of the source multimap. This method is also commonly called transform or map.e.g. return multimap.collectKeyMultiValues(each -> each + 1, Person::getLastName);
- Specified by:
collectKeyMultiValues
in interfaceMultimap<K,V>
- Specified by:
collectKeyMultiValues
in interfaceMutableBagIterableMultimap<K,V>
- Specified by:
collectKeyMultiValues
in interfaceMutableBagMultimap<K,V>
- Specified by:
collectKeyMultiValues
in interfaceMutableMultimap<K,V>
- Specified by:
collectKeyMultiValues
in interfaceUnsortedBagMultimap<K,V>
- Parameters:
keyFunction
-Function
to use transformation to get the keyvalueFunction
-Function
to use transformation to get the values- Returns:
- a new
Multimap
, which contains elements as a result of the transformation
-
collectValues
Description copied from interface:Multimap
Returns a new multimap with the results of applying the specified function on each value of the source multimap. This method is also commonly called transform or map.e.g. return multimap.collectValues(new Function<Person, String>() { public String valueOf(Person person) { return person.getLastName(); } });
- Specified by:
collectValues
in interfaceMultimap<K,V>
- Specified by:
collectValues
in interfaceMutableBagIterableMultimap<K,V>
- Specified by:
collectValues
in interfaceMutableBagMultimap<K,V>
- Specified by:
collectValues
in interfaceMutableMultimap<K,V>
- Specified by:
collectValues
in interfaceUnsortedBagMultimap<K,V>
- Parameters:
function
- aFunction
to use for transformation- Returns:
Multimap
, which contains elements as a result of the transformation
-
asSynchronized
Description copied from interface:MutableMultimap
Returns a synchronized wrapper backed by this multimap. The preferred way of iterating over a synchronized multimap is to use the forEachKey(), forEachValue(), forEachKeyValue() and forEachKeyMultiValues methods which are properly synchronized internally.MutableMultimap synchedMultimap = multimap.asSynchronized(); synchedMultimap.forEachKey(key -> ... ); synchedMultimap.forEachValue(value -> ... ); synchedMultimap.forEachKeyValue((key, value) -> ... ); synchedMultimap.forEachKeyMultiValues((key, values) -> ... );
If you want to iterate imperatively over the keySet(), keysView(), valuesView(), or other views, you will need to protect the iteration by wrapping the code in a synchronized block on the multimap.
- Specified by:
asSynchronized
in interfaceMutableBagIterableMultimap<K,V>
- Specified by:
asSynchronized
in interfaceMutableBagMultimap<K,V>
- Specified by:
asSynchronized
in interfaceMutableMultimap<K,V>
- Returns:
- a synchronized view of this multimap.
- See Also:
MutableMapIterable.asSynchronized()
-