K - the key typeE - V - the value typepublic class Multimap<K,E,V extends Collection<E>> extends Object
Map, but in which each key may be associated with multiple values.
CommonUtil.newMultimap(Supplier, Supplier),
CommonUtil.newListMultimap(),
CommonUtil.newListMultimap(Class, Class),
CommonUtil.newListMultimap(Supplier, Supplier),
CommonUtil.newSetMultimap(),
CommonUtil.newSetMultimap(Class, Class),
CommonUtil.newSetMultimap(Supplier, Supplier)| Modifier and Type | Method and Description |
|---|---|
<X extends Exception> |
accept(Throwables.Consumer<? super Multimap<K,E,V>,X> action) |
<R,X extends Exception> |
apply(Throwables.Function<? super Multimap<K,E,V>,R,X> func) |
void |
clear() |
<X extends Exception> |
compute(K key,
Throwables.BiFunction<? super K,? super V,? extends V,X> remappingFunction)
The implementation is equivalent to performing the following steps for this Multimap:
|
<X extends Exception> |
computeIfAbsent(K key,
Throwables.Function<? super K,? extends V,X> mappingFunction)
The implementation is equivalent to performing the following steps for this Multimap:
|
<X extends Exception> |
computeIfPresent(K key,
Throwables.BiFunction<? super K,? super V,? extends V,X> remappingFunction)
The implementation is equivalent to performing the following steps for this Multimap:
|
static <K,E,V extends Collection<E>,M extends Multimap<K,E,V>> |
concat(Map<? extends K,? extends E> a,
Map<? extends K,? extends E> b,
IntFunction<? extends M> multimapSupplier) |
static <K,E,V extends Collection<E>,M extends Multimap<K,E,V>> |
concat(Map<? extends K,? extends E> a,
Map<? extends K,? extends E> b,
Map<? extends K,? extends E> c,
IntFunction<? extends M> multimapSupplier) |
boolean |
contains(Object key,
Object e) |
boolean |
containsAll(Object key,
Collection<?> c) |
boolean |
containsKey(Object key) |
boolean |
containsValue(Object e) |
Multimap<K,E,V> |
copy() |
Set<Map.Entry<K,V>> |
entrySet() |
boolean |
equals(Object obj) |
<X extends Exception> |
filter(Throwables.BiPredicate<? super K,? super V,X> filter) |
<X extends Exception> |
filterByKey(Throwables.Predicate<? super K,X> filter)
Filter by key.
|
<X extends Exception> |
filterByValue(Throwables.Predicate<? super V,X> filter)
Filter by value.
|
<X extends Exception> |
flatForEach(Throwables.BiConsumer<? super K,? super E,X> action)
Flat for each.
|
<X extends Exception> |
flatForEachValue(Throwables.Consumer<? super E,X> action)
Flat for each value.
|
static <K,E,V extends Collection<K>,M extends Multimap<E,K,V>> |
flatInvertFrom(Map<K,? extends Collection<? extends E>> map,
IntFunction<? extends M> multimapSupplier)
Flat invert from.
|
List<E> |
flatValues() |
<R extends Collection<E>> |
flatValues(IntFunction<R> supplier) |
<X extends Exception> |
forEach(Throwables.BiConsumer<? super K,? super V,X> action) |
<X extends Exception> |
forEachKey(Throwables.Consumer<? super K,X> action)
For each key.
|
<X extends Exception> |
forEachValue(Throwables.Consumer<? super V,X> action)
For each value.
|
static <T,K,V extends Collection<T>,M extends Multimap<K,T,V>,X extends Exception> |
from(Collection<? extends T> c,
Throwables.Function<? super T,? extends K,X> keyMapper,
IntFunction<? extends M> multimapSupplier) |
static <T,K,E,V extends Collection<E>,M extends Multimap<K,E,V>,X extends Exception,X2 extends Exception> |
from(Collection<? extends T> c,
Throwables.Function<? super T,? extends K,X> keyMapper,
Throwables.Function<? super T,? extends E,X2> valueExtractor,
IntFunction<? extends M> multimapSupplier) |
static <K,E,V extends Collection<E>,M extends Multimap<K,E,V>> |
from(Map<? extends K,? extends E> map,
IntFunction<? extends M> multimapSupplier) |
static <K,E,V extends Collection<E>,M extends Multimap<K,E,V>> |
fromm(Map<? extends K,? extends Collection<? extends E>> map,
IntFunction<? extends M> multimapSupplier) |
V |
get(Object key) |
V |
getOrDefault(Object key,
V defaultValue)
Gets the or default.
|
int |
hashCode() |
<VV extends Collection<K>,M extends Multimap<E,K,VV>> |
inverse(IntFunction<? extends M> multimapSupplier) |
static <K,E,V extends Collection<K>,M extends Multimap<E,K,V>> |
invertFrom(Map<K,E> map,
IntFunction<? extends M> multimapSupplier) |
static <K,E,V extends Collection<E>,VV extends Collection<K>,M extends Multimap<E,K,VV>> |
invertFrom(Multimap<K,E,V> multimap,
IntFunction<? extends M> multimapSupplier) |
boolean |
isEmpty()
Checks if is empty.
|
Set<K> |
keySet() |
<X extends Exception> |
merge(K key,
E e,
Throwables.BiFunction<? super V,? super E,? extends V,X> remappingFunction)
The implementation is equivalent to performing the following steps for this Multimap:
|
<X extends Exception> |
merge(K key,
V value,
Throwables.BiFunction<? super V,? super V,? extends V,X> remappingFunction)
The implementation is equivalent to performing the following steps for this Multimap:
|
boolean |
put(K key,
E e) |
boolean |
putAll(K key,
Collection<? extends E> c) |
boolean |
putAll(Map<? extends K,? extends E> m) |
boolean |
putAll(Multimap<? extends K,? extends E,? extends Collection<? extends E>> m) |
boolean |
putAllIfKeyAbsent(K key,
Collection<? extends E> c)
If the specified key is not already associated with any value (or is mapped
to
null) associates it with the given values in the specified collection
and returns true, else returns false. |
boolean |
putIfAbsent(K key,
E e)
If the specified value is not already associated with the specified key
associates it with the given key and returns
true, else returns false. |
boolean |
putIfKeyAbsent(K key,
E e)
If the specified key is not already associated with any value (or is mapped
to
null) associates it with the given value and returns true, else returns false. |
boolean |
remove(Object key,
Object e) |
boolean |
removeAll(Map<?,? extends Collection<?>> m)
ListMultimap |
boolean |
removeAll(Multimap<?,?,?> m)
Removes the all.
|
V |
removeAll(Object key)
Removes the all.
|
boolean |
removeAll(Object key,
Collection<?> c)
Removes the all.
|
<X extends Exception> |
removeAllIf(Collection<?> values,
Throwables.BiPredicate<? super K,? super V,X> predicate)
Remove the specified values (all occurrences) from the value set associated with keys which satisfy the specified
predicate. |
<X extends Exception> |
removeAllIf(Collection<?> values,
Throwables.Predicate<? super K,X> predicate)
Remove the specified values (all occurrences) from the value set associated with keys which satisfy the specified
predicate. |
<X extends Exception> |
removeAllIf(Throwables.BiPredicate<? super K,? super V,X> predicate)
Remove all the values associated with keys which satisfy the specified
predicate. |
<X extends Exception> |
removeAllIf(Throwables.Predicate<? super K,X> predicate)
Remove all the values associated with keys which satisfy the specified
predicate. |
<X extends Exception> |
removeIf(E value,
Throwables.BiPredicate<? super K,? super V,X> predicate)
Remove the specified value (one occurrence) from the value set associated with keys which satisfy the specified
predicate. |
<X extends Exception> |
removeIf(E value,
Throwables.Predicate<? super K,X> predicate)
Remove the specified value (one occurrence) from the value set associated with keys which satisfy the specified
predicate. |
boolean |
replace(K key,
E oldValue,
E newValue)
Replace the specified
oldValue (one occurrence) with the specified newValue. |
boolean |
replaceAll(K key,
Collection<? extends E> oldValues,
E newValue)
Deprecated.
|
boolean |
replaceAll(K key,
E oldValue,
E newValue)
Replace the specified
oldValue (all occurrences) with the specified newValue. |
<X extends Exception> |
replaceAll(Throwables.BiFunction<? super K,? super V,? extends V,X> function)
The associated keys will be removed if null or empty values are returned by the specified
function. |
<X extends Exception> |
replaceAllIf(Throwables.BiPredicate<? super K,? super V,X> predicate,
Collection<? extends E> oldValues,
E newValue)
Deprecated.
|
<X extends Exception> |
replaceAllIf(Throwables.BiPredicate<? super K,? super V,X> predicate,
E oldValue,
E newValue)
Replace the specified
oldValue (all occurrences) from the value set associated with keys which satisfy the specified predicate with the specified newValue. |
<X extends Exception> |
replaceAllIf(Throwables.Predicate<? super K,X> predicate,
Collection<? extends E> oldValues,
E newValue)
Deprecated.
|
<X extends Exception> |
replaceAllIf(Throwables.Predicate<? super K,X> predicate,
E oldValue,
E newValue)
Replace the specified
oldValue (all occurrences) from the value set associated with keys which satisfy the specified predicate with the specified newValue. |
<X extends Exception> |
replaceIf(Throwables.BiPredicate<? super K,? super V,X> predicate,
E oldValue,
E newValue)
Replace the specified
oldValue (one occurrence) from the value set associated with keys which satisfy the specified predicate with the specified newValue. |
<X extends Exception> |
replaceIf(Throwables.Predicate<? super K,X> predicate,
E oldValue,
E newValue)
Replace the specified
oldValue (one occurrence) from the value set associated with keys which satisfy the specified predicate with the specified newValue. |
int |
size() |
Map<K,V> |
toMap() |
<M extends Map<K,V>> |
toMap(IntFunction<? extends M> supplier) |
Multiset<K> |
toMultiset() |
String |
toString() |
int |
totalCountOfValues()
Returns the total count of all the elements in all values.
|
Map<K,V> |
unwrap()
Returns a view of this multimap as a
Map from each distinct key
to the nonempty collection of that key's associated values. |
Collection<V> |
values() |
static <K,E,V extends Collection<E>> |
wrap(Map<K,V> map,
Supplier<? extends V> valueSupplier) |
public static <K,E,V extends Collection<E>,M extends Multimap<K,E,V>> M from(Map<? extends K,? extends E> map, IntFunction<? extends M> multimapSupplier)
K - the key typeE - V - the value typeM - map - multimapSupplier - public static <K,E,V extends Collection<E>,M extends Multimap<K,E,V>> M fromm(Map<? extends K,? extends Collection<? extends E>> map, IntFunction<? extends M> multimapSupplier)
K - the key typeE - V - the value typeM - map - multimapSupplier - public static <T,K,V extends Collection<T>,M extends Multimap<K,T,V>,X extends Exception> M from(Collection<? extends T> c, Throwables.Function<? super T,? extends K,X> keyMapper, IntFunction<? extends M> multimapSupplier) throws X extends Exception
T - K - the key typeV - the value typeM - X - c - keyMapper - multimapSupplier - X - the xX extends Exceptionpublic static <T,K,E,V extends Collection<E>,M extends Multimap<K,E,V>,X extends Exception,X2 extends Exception> M from(Collection<? extends T> c, Throwables.Function<? super T,? extends K,X> keyMapper, Throwables.Function<? super T,? extends E,X2> valueExtractor, IntFunction<? extends M> multimapSupplier) throws X extends Exception, X2 extends Exception
T - K - the key typeE - V - the value typeM - X - X2 - c - keyMapper - valueExtractor - multimapSupplier - X - the xX2 - the x2X extends Exceptionpublic static <K,E,V extends Collection<K>,M extends Multimap<E,K,V>> M invertFrom(Map<K,E> map, IntFunction<? extends M> multimapSupplier)
K - the key typeE - V - the value typeM - map - multimapSupplier - ListMultimap.invertFrom(Map),
SetMultimap.invertFrom(Map)public static <K,E,V extends Collection<K>,M extends Multimap<E,K,V>> M flatInvertFrom(Map<K,? extends Collection<? extends E>> map, IntFunction<? extends M> multimapSupplier)
K - the key typeE - V - the value typeM - map - multimapSupplier - ListMultimap.flatInvertFrom(Map),
SetMultimap.flatInvertFrom(Map)public static <K,E,V extends Collection<E>,VV extends Collection<K>,M extends Multimap<E,K,VV>> M invertFrom(Multimap<K,E,V> multimap, IntFunction<? extends M> multimapSupplier)
K - the key typeE - V - the value typeVV - M - multimap - multimapSupplier - public static <K,E,V extends Collection<E>,M extends Multimap<K,E,V>> M concat(Map<? extends K,? extends E> a, Map<? extends K,? extends E> b, IntFunction<? extends M> multimapSupplier)
K - the key typeE - V - the value typeM - a - b - multimapSupplier - public static <K,E,V extends Collection<E>,M extends Multimap<K,E,V>> M concat(Map<? extends K,? extends E> a, Map<? extends K,? extends E> b, Map<? extends K,? extends E> c, IntFunction<? extends M> multimapSupplier)
K - the key typeE - V - the value typeM - a - b - c - multimapSupplier - public static <K,E,V extends Collection<E>> Multimap<K,E,V> wrap(Map<K,V> map, Supplier<? extends V> valueSupplier)
K - the key typeE - V - the value typemap - valueSupplier - public V getOrDefault(Object key, V defaultValue)
key - defaultValue - public boolean putIfAbsent(K key, E e)
true, else returns false.key - e - public boolean putIfKeyAbsent(K key, E e)
null) associates it with the given value and returns true, else returns false.key - e - public boolean putAll(K key, Collection<? extends E> c)
key - c - public boolean putAllIfKeyAbsent(K key, Collection<? extends E> c)
null) associates it with the given values in the specified collection
and returns true, else returns false.key - c - public boolean putAll(Multimap<? extends K,? extends E,? extends Collection<? extends E>> m)
m - public V removeAll(Object key)
key - public boolean removeAll(Object key, Collection<?> c)
key - c - public boolean removeAll(Map<?,? extends Collection<?>> m)
ListMultimap listMultimap = ListMultimap.of("a", 1, "b", 2, "a", 2, "a", 2); // -> {a=[1, 2, 2], b=[2]}
listMultimap.removeAll(N.asMap("a", N.asList(2))); // -> {a=[1], b=[2]}
m - public boolean removeAll(Multimap<?,?,?> m)
m - public <X extends Exception> boolean removeIf(E value, Throwables.Predicate<? super K,X> predicate) throws X extends Exception
predicate.X - value - predicate - true if this Multimap is modified by this operation, otherwise false.X - the xX extends Exceptionpublic <X extends Exception> boolean removeIf(E value, Throwables.BiPredicate<? super K,? super V,X> predicate) throws X extends Exception
predicate.X - value - predicate - true if this Multimap is modified by this operation, otherwise false.X - the xX extends Exceptionpublic <X extends Exception> boolean removeAllIf(Collection<?> values, Throwables.Predicate<? super K,X> predicate) throws X extends Exception
predicate.X - values - predicate - true if this Multimap is modified by this operation, otherwise false.X - the xX extends Exceptionpublic <X extends Exception> boolean removeAllIf(Collection<?> values, Throwables.BiPredicate<? super K,? super V,X> predicate) throws X extends Exception
predicate.X - values - predicate - true if this Multimap is modified by this operation, otherwise false.X - the xX extends Exceptionpublic <X extends Exception> boolean removeAllIf(Throwables.Predicate<? super K,X> predicate) throws X extends Exception
predicate.X - predicate - true if this Multimap is modified by this operation, otherwise false.X - the xX extends Exceptionpublic <X extends Exception> boolean removeAllIf(Throwables.BiPredicate<? super K,? super V,X> predicate) throws X extends Exception
predicate.X - predicate - true if this Multimap is modified by this operation, otherwise false.X - the xX extends Exceptionpublic boolean replace(K key, E oldValue, E newValue)
oldValue (one occurrence) with the specified newValue.
False is returned if no oldValue is found.key - oldValue - newValue - true if this Multimap is modified by this operation, otherwise false.public boolean replaceAll(K key, E oldValue, E newValue)
oldValue (all occurrences) with the specified newValue.
False is returned if no oldValue is found.key - oldValues - newValue - true if this Multimap is modified by this operation, otherwise false.@Deprecated public boolean replaceAll(K key, Collection<? extends E> oldValues, E newValue)
oldValues (all occurrences) with single specified newValue.
False is returned if no oldValue is found.key - oldValues - newValue - true if this Multimap is modified by this operation, otherwise false.public <X extends Exception> boolean replaceIf(Throwables.Predicate<? super K,X> predicate, E oldValue, E newValue) throws X extends Exception
oldValue (one occurrence) from the value set associated with keys which satisfy the specified predicate with the specified newValue.X - predicate - oldValue - newValue - true if this Multimap is modified by this operation, otherwise false.X - the xX extends Exceptionpublic <X extends Exception> boolean replaceIf(Throwables.BiPredicate<? super K,? super V,X> predicate, E oldValue, E newValue) throws X extends Exception
oldValue (one occurrence) from the value set associated with keys which satisfy the specified predicate with the specified newValue.X - predicate - oldValue - newValue - true if this Multimap is modified by this operation, otherwise false.X - the xX extends Exceptionpublic <X extends Exception> boolean replaceAllIf(Throwables.Predicate<? super K,X> predicate, E oldValue, E newValue) throws X extends Exception
oldValue (all occurrences) from the value set associated with keys which satisfy the specified predicate with the specified newValue.X - predicate - oldValue - newValue - true if this Multimap is modified by this operation, otherwise false.X - the xX extends Exceptionpublic <X extends Exception> boolean replaceAllIf(Throwables.BiPredicate<? super K,? super V,X> predicate, E oldValue, E newValue) throws X extends Exception
oldValue (all occurrences) from the value set associated with keys which satisfy the specified predicate with the specified newValue.X - predicate - oldValue - newValue - true if this Multimap is modified by this operation, otherwise false.X - the xX extends Exception@Deprecated public <X extends Exception> boolean replaceAllIf(Throwables.Predicate<? super K,X> predicate, Collection<? extends E> oldValues, E newValue) throws X extends Exception
oldValue (all occurrences) from the value set associated with keys which satisfy the specified predicate with single specified newValue.X - predicate - oldValues - newValue - true if this Multimap is modified by this operation, otherwise false.X - the xX extends Exception@Deprecated public <X extends Exception> boolean replaceAllIf(Throwables.BiPredicate<? super K,? super V,X> predicate, Collection<? extends E> oldValues, E newValue) throws X extends Exception
oldValue (all occurrences) from the value set associated with keys which satisfy the specified predicate with single specified newValue.X - predicate - oldValues - newValue - true if this Multimap is modified by this operation, otherwise false.X - the xX extends Exceptionpublic <X extends Exception> void replaceAll(Throwables.BiFunction<? super K,? super V,? extends V,X> function) throws X extends Exception
function.X - function - X - the xX extends Exceptionpublic boolean containsKey(Object key)
key - public boolean containsValue(Object e)
e - public boolean containsAll(Object key, Collection<?> c)
key - c - public <X extends Exception> Multimap<K,E,V> filterByKey(Throwables.Predicate<? super K,X> filter) throws X extends Exception
X - filter - X - the xX extends Exceptionpublic <X extends Exception> Multimap<K,E,V> filterByValue(Throwables.Predicate<? super V,X> filter) throws X extends Exception
X - filter - X - the xX extends Exceptionpublic <X extends Exception> Multimap<K,E,V> filter(Throwables.BiPredicate<? super K,? super V,X> filter) throws X extends Exception
X - filter - X - the xX extends Exceptionpublic <X extends Exception> void forEach(Throwables.BiConsumer<? super K,? super V,X> action) throws X extends Exception
X - action - X - the xX extends Exceptionpublic <X extends Exception> void flatForEach(Throwables.BiConsumer<? super K,? super E,X> action) throws X extends Exception
X - action - X - the xX extends Exceptionpublic <X extends Exception> void forEachKey(Throwables.Consumer<? super K,X> action) throws X extends Exception
X - action - X - the xX extends Exceptionpublic <X extends Exception> void forEachValue(Throwables.Consumer<? super V,X> action) throws X extends Exception
X - action - X - the xX extends Exceptionpublic <X extends Exception> void flatForEachValue(Throwables.Consumer<? super E,X> action) throws X extends Exception
X - action - X - the xX extends Exceptionpublic <X extends Exception> V computeIfAbsent(K key, Throwables.Function<? super K,? extends V,X> mappingFunction) throws X extends Exception
final V oldValue = get(key);
if (N.notNullOrEmpty(oldValue)) {
return oldValue;
}
final V newValue = mappingFunction.apply(key);
if (N.notNullOrEmpty(newValue)) {
valueMap.put(key, newValue);
}
return newValue;
X - key - mappingFunction - X - the xX extends Exceptionpublic <X extends Exception> V computeIfPresent(K key, Throwables.BiFunction<? super K,? super V,? extends V,X> remappingFunction) throws X extends Exception
final V oldValue = get(key);
if (N.isNullOrEmpty(oldValue)) {
return oldValue;
}
final V newValue = remappingFunction.apply(key, oldValue);
if (N.notNullOrEmpty(newValue)) {
valueMap.put(key, newValue);
} else {
valueMap.remove(key);
}
return newValue;
X - key - remappingFunction - X - the xX extends Exceptionpublic <X extends Exception> V compute(K key, Throwables.BiFunction<? super K,? super V,? extends V,X> remappingFunction) throws X extends Exception
final V oldValue = get(key);
final V newValue = remappingFunction.apply(key, oldValue);
if (N.notNullOrEmpty(newValue)) {
valueMap.put(key, newValue);
} else {
if (oldValue != null) {
valueMap.remove(key);
}
}
return newValue;
X - key - remappingFunction - X - the xX extends Exceptionpublic <X extends Exception> V merge(K key, V value, Throwables.BiFunction<? super V,? super V,? extends V,X> remappingFunction) throws X extends Exception
final V oldValue = get(key);
final V newValue = oldValue == null ? value : remappingFunction.apply(oldValue, value);
if (N.notNullOrEmpty(newValue)) {
valueMap.put(key, newValue);
} else {
if (oldValue != null) {
valueMap.remove(key);
}
}
return newValue;
X - key - value - remappingFunction - X - the xX extends Exceptionpublic <X extends Exception> V merge(K key, E e, Throwables.BiFunction<? super V,? super E,? extends V,X> remappingFunction) throws X extends Exception
final V oldValue = get(key);
if (N.isNullOrEmpty(oldValue)) {
put(key, e);
return get(key);
}
final V newValue = remappingFunction.apply(oldValue, e);
if (N.notNullOrEmpty(newValue)) {
valueMap.put(key, newValue);
} else {
if (oldValue != null) {
valueMap.remove(key);
}
}
return newValue;
X - key - e - remappingFunction - X - the xX extends Exceptionpublic <VV extends Collection<K>,M extends Multimap<E,K,VV>> M inverse(IntFunction<? extends M> multimapSupplier)
public Collection<V> values()
public <R extends Collection<E>> R flatValues(IntFunction<R> supplier)
R - supplier - public <M extends Map<K,V>> M toMap(IntFunction<? extends M> supplier)
M - supplier - public Map<K,V> unwrap()
Map from each distinct key
to the nonempty collection of that key's associated values.
Changes to the returned map or the collections that serve as its values will update the underlying multimap, and vice versa.
public void clear()
public int size()
public int totalCountOfValues()
public boolean isEmpty()
public <R,X extends Exception> R apply(Throwables.Function<? super Multimap<K,E,V>,R,X> func) throws X extends Exception
R - X - func - X - the xX extends Exceptionpublic <X extends Exception> void accept(Throwables.Consumer<? super Multimap<K,E,V>,X> action) throws X extends Exception
X - action - X - the xX extends Exceptionpublic boolean equals(Object obj)
Copyright © 2021. All rights reserved.