Top Methods
org.eclipse.collections.api.multimap

public Interface MutableMultimap<K, V>

extends Multimap<K, V>
Known Direct Subinterfaces
org.eclipse.collections.api.multimap.bag.MutableBagIterableMultimap, org.eclipse.collections.api.multimap.list.MutableListMultimap, org.eclipse.collections.api.multimap.set.MutableSetIterableMultimap
Imports
java.util.Arrays, .Objects, org.eclipse.collections.api.RichIterable, org.eclipse.collections.api.block.function.Function, .Function2, org.eclipse.collections.api.block.predicate.Predicate2, org.eclipse.collections.api.collection.MutableCollection, org.eclipse.collections.api.map.MutableMapIterable, org.eclipse.collections.api.tuple.Pair

Since
1.0

Method Summary

Modifier and TypeMethod and Description
public default boolean
add(Pair<? extends K, ? extends V>
key value pair to add in the multimap
keyValuePair
)

Modification operation similar to put, however, takes the key-value pair as the input.

public MutableMultimap<K, V>

Returns:

a synchronized view of this multimap.
asSynchronized
()

Returns a synchronized wrapper backed by this multimap.

public void
public <K2, V2> MutableMultimap<K2, V2>
collectKeyMultiValues(Function<? super K, ? extends K2> keyFunction, Function<? super V, ? extends V2> valueFunction)

Redeclares org.eclipse.collections.api.multimap.Multimap.collectKeyMultiValues.

Returns a new multimap with the results of applying the specified keyFunction and valueFunction on each key and corresponding values of the source multimap.

public <K2, V2> MutableMultimap<K2, V2>
collectKeysValues(Function2<? super K, ? super V, Pair<K2, V2>> function)

Redeclares org.eclipse.collections.api.multimap.Multimap.collectKeysValues.

Returns a new multimap with the results of applying the specified function on each key and value of the source multimap.

public <V2> MutableMultimap<K, V2>
collectValues(Function<? super V, ? extends V2> function)

Redeclares org.eclipse.collections.api.multimap.Multimap.collectValues.

Returns a new multimap with the results of applying the specified function on each value of the source multimap.

public MutableMultimap<V, K>
flip()

Redeclares org.eclipse.collections.api.multimap.Multimap.flip.

Given a Multimap from Domain -> Range return a multimap from Range -> Domain.

public MutableCollection<V>
get(K key)

Redeclares org.eclipse.collections.api.multimap.Multimap.get.

Returns a view of all values associated with the given key.

public MutableCollection<V>
getIfAbsentPutAll(K key, Iterable<? extends V> values)

Puts values into multimap if there are no values already associated with key.

public MutableMultimap<K, V>
newEmpty()

Redeclares org.eclipse.collections.api.multimap.Multimap.newEmpty.

Creates a new instance of the same implementation type, using the default capacity and growth parameters.

public boolean
put(K key, V value)

public boolean
putAll(K key, Iterable<? extends V> values)

public <KK extends K, VV extends V> boolean
putAll(Multimap<KK, VV> multimap)

public default boolean
putAllPairs(Pair<? extends K, ? extends V>... pairs)

public default boolean
putAllPairs(Iterable<? extends Pair<? extends K, ? extends V>> pairs)

public MutableMultimap<K, V>
rejectKeysMultiValues(Predicate2<? super K, ? super RichIterable<V>> predicate)

Redeclares org.eclipse.collections.api.multimap.Multimap.rejectKeysMultiValues.

Returns all elements of the source multimap that don't satisfy the predicate.

public MutableMultimap<K, V>
rejectKeysValues(Predicate2<? super K, ? super V> predicate)

Redeclares org.eclipse.collections.api.multimap.Multimap.rejectKeysValues.

Returns all elements of the source multimap that don't satisfy the predicate.

public boolean
remove(Object key, Object value)

public RichIterable<V>
public RichIterable<V>
replaceValues(K key, Iterable<? extends V> values)

public MutableMultimap<K, V>
selectKeysMultiValues(Predicate2<? super K, ? super RichIterable<V>> predicate)

Redeclares org.eclipse.collections.api.multimap.Multimap.selectKeysMultiValues.

Returns all elements of the source multimap that satisfies the predicate.

public MutableMultimap<K, V>
selectKeysValues(Predicate2<? super K, ? super V> predicate)

Redeclares org.eclipse.collections.api.multimap.Multimap.selectKeysValues.

Returns all elements of the source multimap that satisfies the predicate.

public default MutableMultimap<K, V>
withKeyMultiValues(K key, V... values)

Puts the key / values combination into the MutableMultimap and returns the MutableMultimap (this).

public default MutableMultimap<K, V>
withKeyValue(K key, V value)

Puts the key / value combination into the MutableMultimap and returns the MutableMultimap (this).

Inherited from org.eclipse.collections.api.multimap.Multimap:
collectKeyMultiValuescollectKeysValuescollectValuescontainsKeycontainsKeyAndValuecontainsValueequalsforEachKeyforEachKeyMultiValuesforEachKeyValueforEachValuehashCodeisEmptykeyBagkeyMultiValuePairsViewkeySetkeysViewkeyValuePairsViewmultiValuesViewnotEmptyrejectKeysMultiValuesrejectKeysValuesselectKeysMultiValuesselectKeysValuessizesizeDistincttoImmutabletoMaptoMaptoMutablevaluesView

Method Detail

addback to summary
public default boolean add(Pair<? extends K, ? extends V> keyValuePair)

Modification operation similar to put, however, takes the key-value pair as the input.

Parameters
keyValuePair:Pair<? extends K, ? extends V>

key value pair to add in the multimap

Since
6.0
See Also
put(Object, Object)
asSynchronizedback to summary
public MutableMultimap<K, V> asSynchronized()

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.

Returns:MutableMultimap<K, V>

a synchronized view of this multimap.

Since
8.0
See Also
MutableMapIterable#asSynchronized()
clearback to summary
public void clear()
collectKeyMultiValuesback to summary
public <K2, V2> MutableMultimap<K2, V2> collectKeyMultiValues(Function<? super K, ? extends K2> keyFunction, Function<? super V, ? extends V2> valueFunction)

Redeclares org.eclipse.collections.api.multimap.Multimap.collectKeyMultiValues.

Doc from org.eclipse.collections.api.multimap.Multimap.collectKeyMultiValues.

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);
Annotations
@Override
collectKeysValuesback to summary
public <K2, V2> MutableMultimap<K2, V2> collectKeysValues(Function2<? super K, ? super V, Pair<K2, V2>> function)

Redeclares org.eclipse.collections.api.multimap.Multimap.collectKeysValues.

Doc from org.eclipse.collections.api.multimap.Multimap.collectKeysValues.

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());
    }
});
Annotations
@Override
collectValuesback to summary
public <V2> MutableMultimap<K, V2> collectValues(Function<? super V, ? extends V2> function)

Redeclares org.eclipse.collections.api.multimap.Multimap.collectValues.

Doc from org.eclipse.collections.api.multimap.Multimap.collectValues.

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();
    }
});
Annotations
@Override
flipback to summary
public MutableMultimap<V, K> flip()

Redeclares org.eclipse.collections.api.multimap.Multimap.flip.

Doc from org.eclipse.collections.api.multimap.Multimap.flip.

Given a Multimap from Domain -> Range return a multimap from Range -> Domain.

Annotations
@Override
getback to summary
public MutableCollection<V> get(K key)

Redeclares org.eclipse.collections.api.multimap.Multimap.get.

Doc from org.eclipse.collections.api.multimap.Multimap.get.

Returns a view of all values associated with the given key.

If the given key does not exist, an empty RichIterable is returned.

Annotations
@Override
getIfAbsentPutAllback to summary
public MutableCollection<V> getIfAbsentPutAll(K key, Iterable<? extends V> values)

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 of Multimap#get(Object)

Since
10.0
newEmptyback to summary
public MutableMultimap<K, V> newEmpty()

Redeclares org.eclipse.collections.api.multimap.Multimap.newEmpty.

Doc from org.eclipse.collections.api.multimap.Multimap.newEmpty.

Creates a new instance of the same implementation type, using the default capacity and growth parameters.

Annotations
@Override
putback to summary
public boolean put(K key, V value)
putAllback to summary
public boolean putAll(K key, Iterable<? extends V> values)
putAllback to summary
public <KK extends K, VV extends V> boolean putAll(Multimap<KK, VV> multimap)
putAllPairsback to summary
public default boolean putAllPairs(Pair<? extends K, ? extends V>... pairs)
putAllPairsback to summary
public default boolean putAllPairs(Iterable<? extends Pair<? extends K, ? extends V>> pairs)
rejectKeysMultiValuesback to summary
public MutableMultimap<K, V> rejectKeysMultiValues(Predicate2<? super K, ? super RichIterable<V>> predicate)

Redeclares org.eclipse.collections.api.multimap.Multimap.rejectKeysMultiValues.

Doc from org.eclipse.collections.api.multimap.Multimap.rejectKeysMultiValues.

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);
    }
});
Annotations
@Override
rejectKeysValuesback to summary
public MutableMultimap<K, V> rejectKeysValues(Predicate2<? super K, ? super V> predicate)

Redeclares org.eclipse.collections.api.multimap.Multimap.rejectKeysValues.

Doc from org.eclipse.collections.api.multimap.Multimap.rejectKeysValues.

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"));
    }
});
Annotations
@Override
removeback to summary
public boolean remove(Object key, Object value)
removeAllback to summary
public RichIterable<V> removeAll(Object key)
replaceValuesback to summary
public RichIterable<V> replaceValues(K key, Iterable<? extends V> values)
selectKeysMultiValuesback to summary
public MutableMultimap<K, V> selectKeysMultiValues(Predicate2<? super K, ? super RichIterable<V>> predicate)

Redeclares org.eclipse.collections.api.multimap.Multimap.selectKeysMultiValues.

Doc from org.eclipse.collections.api.multimap.Multimap.selectKeysMultiValues.

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);
    }
});
Annotations
@Override
selectKeysValuesback to summary
public MutableMultimap<K, V> selectKeysValues(Predicate2<? super K, ? super V> predicate)

Redeclares org.eclipse.collections.api.multimap.Multimap.selectKeysValues.

Doc from org.eclipse.collections.api.multimap.Multimap.selectKeysValues.

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"));
    }
});
Annotations
@Override
withKeyMultiValuesback to summary
public default MutableMultimap<K, V> withKeyMultiValues(K key, V... values)

Puts the key / values combination into the MutableMultimap and returns the MutableMultimap (this).

Since
11.1
withKeyValueback to summary
public default MutableMultimap<K, V> withKeyValue(K key, V value)

Puts the key / value combination into the MutableMultimap and returns the MutableMultimap (this).

Since
11.1