Package com.landawn.abacus.util
Class ListMultimap<K,E>
java.lang.Object
com.landawn.abacus.util.Multimap<K,E,List<E>>
com.landawn.abacus.util.ListMultimap<K,E>
- Type Parameters:
K
- the key typeE
-
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,
E> ListMultimap <K, E> concat
(Collection<? extends Map<? extends K, ? extends E>> c) Creates a new instance of ListMultimap by concatenating the key-value pairs from a collection of maps.static <K,
E> ListMultimap <K, E> Creates a new instance of ListMultimap by concatenating the key-value pairs from two specified maps.static <K,
E> ListMultimap <K, E> concat
(Map<? extends K, ? extends E> a, Map<? extends K, ? extends E> b, Map<? extends K, ? extends E> c) Creates a new instance of ListMultimap by concatenating the key-value pairs from three specified maps.copy()
Returns a new ListMultimap and copies all key-value pairs from this ListMultimap to the new one.static <T,
K> ListMultimap <K, T> create
(Collection<? extends T> c, Function<? super T, ? extends K> keyMapper) Creates a new instance of ListMultimap from a given collection and a key mapper function.static <T,
K, E> ListMultimap <K, E> create
(Collection<? extends T> c, Function<? super T, ? extends K> keyMapper, Function<? super T, ? extends E> valueExtractor) Creates a new instance of ListMultimap from a given collection, a key mapper function, and a value extractor function.static <K,
E> ListMultimap <K, E> Creates a new instance of ListMultimap with the key-value pairs from the specified map.filter
(BiPredicate<? super K, ? super List<E>> filter) Filters the ListMultimap based on the provided key-value pair filter.filterByKey
(Predicate<? super K> filter) Filters the ListMultimap based on the provided key filter.filterByValue
(Predicate<? super List<E>> filter) Filters the ListMultimap based on the provided value filter.Return the first value for the given key, ornull
if no value is found.getFirstOrDefault
(K key, E defaultValue) Return the first value for the given key, ordefaultValue
if no value is found.inverse()
Inverts the ListMultimap, swapping keys with values.static <K,
E> ListMultimap <K, E> of
(K k1, E v1) Creates a new instance of ListMultimap with one key-value pair.static <K,
E> ListMultimap <K, E> of
(K k1, E v1, K k2, E v2) Creates a new instance of ListMultimap with two key-value pairs.static <K,
E> ListMultimap <K, E> of
(K k1, E v1, K k2, E v2, K k3, E v3) Creates a new instance of ListMultimap with three key-value pairs.static <K,
E> ListMultimap <K, E> of
(K k1, E v1, K k2, E v2, K k3, E v3, K k4, E v4) Creates a new instance of ListMultimap with four key-value pairs.static <K,
E> ListMultimap <K, E> of
(K k1, E v1, K k2, E v2, K k3, E v3, K k4, E v4, K k5, E v5) Creates a new instance of ListMultimap with five key-value pairs.static <K,
E> ListMultimap <K, E> of
(K k1, E v1, K k2, E v2, K k3, E v3, K k4, E v4, K k5, E v5, K k6, E v6) Creates a new instance of ListMultimap with six key-value pairs.static <K,
E> ListMultimap <K, E> of
(K k1, E v1, K k2, E v2, K k3, E v3, K k4, E v4, K k5, E v5, K k6, E v6, K k7, E v7) Creates a new instance of ListMultimap with seven key-value pairs.Converts the current ListMultimap into an ImmutableMap.toImmutableMap
(IntFunction<? extends Map<K, ImmutableList<E>>> mapSupplier) Converts the current ListMultimap into an ImmutableMap using a provided map supplier.static <K,
E, V extends List<E>>
ListMultimap<K, E> Wraps the provided map into a ListMultimap.static <K,
E, V extends List<E>>
ListMultimap<K, E> Wraps the provided map into a ListMultimap with a custom list supplier.Methods inherited from class com.landawn.abacus.util.Multimap
accept, acceptIfNotEmpty, apply, applyIfNotEmpty, clear, compute, computeIfAbsent, computeIfPresent, contains, containsAll, containsKey, containsValue, entrySet, entryStream, equals, flatForEach, flatForEachValue, flatValues, flatValues, forEach, forEachKey, forEachValue, get, getOrDefault, hashCode, inverse, isEmpty, iterator, keySet, merge, merge, put, put, putIfAbsent, putIfKeyAbsent, putMany, putMany, putMany, putManyIfKeyAbsent, removeAll, removeAllIf, removeAllIf, removeMany, removeMany, removeMany, removeManyIf, removeManyIf, removeOne, removeOne, removeOneIf, removeOneIf, replaceAll, replaceAllWithOne, replaceAllWithOneIf, replaceAllWithOneIf, replaceManyWithOne, replaceManyWithOneIf, replaceManyWithOneIf, replaceOne, replaceOneIf, replaceOneIf, size, stream, toMap, toMap, toMultiset, toString, totalCountOfValues, values
Methods inherited from interface java.lang.Iterable
forEach, spliterator
-
Method Details
-
of
Creates a new instance of ListMultimap with one key-value pair.- Type Parameters:
K
- the type of the keyE
- the type of the value- Parameters:
k1
- the key of the key-value pairv1
- the value of the key-value pair- Returns:
- a new instance of ListMultimap with the specified key-value pair
-
of
Creates a new instance of ListMultimap with two key-value pairs.- Type Parameters:
K
- the type of the keysE
- the type of the values- Parameters:
k1
- the first key of the key-value pairsv1
- the first value of the key-value pairsk2
- the second key of the key-value pairsv2
- the second value of the key-value pairs- Returns:
- a new instance of ListMultimap with the specified key-value pairs
-
of
Creates a new instance of ListMultimap with three key-value pairs.- Type Parameters:
K
- the type of the keysE
- the type of the values- Parameters:
k1
- the first key of the key-value pairsv1
- the first value of the key-value pairsk2
- the second key of the key-value pairsv2
- the second value of the key-value pairsk3
- the third key of the key-value pairsv3
- the third value of the key-value pairs- Returns:
- a new instance of ListMultimap with the specified key-value pairs
-
of
Creates a new instance of ListMultimap with four key-value pairs.- Type Parameters:
K
- the type of the keysE
- the type of the values- Parameters:
k1
- the first key of the key-value pairsv1
- the first value of the key-value pairsk2
- the second key of the key-value pairsv2
- the second value of the key-value pairsk3
- the third key of the key-value pairsv3
- the third value of the key-value pairsk4
- the fourth key of the key-value pairsv4
- the fourth value of the key-value pairs- Returns:
- a new instance of ListMultimap with the specified key-value pairs
-
of
public static <K,E> ListMultimap<K,E> of(K k1, E v1, K k2, E v2, K k3, E v3, K k4, E v4, K k5, E v5) Creates a new instance of ListMultimap with five key-value pairs.- Type Parameters:
K
- the type of the keysE
- the type of the values- Parameters:
k1
- the first key of the key-value pairsv1
- the first value of the key-value pairsk2
- the second key of the key-value pairsv2
- the second value of the key-value pairsk3
- the third key of the key-value pairsv3
- the third value of the key-value pairsk4
- the fourth key of the key-value pairsv4
- the fourth value of the key-value pairsk5
- the fifth key of the key-value pairsv5
- the fifth value of the key-value pairs- Returns:
- a new instance of ListMultimap with the specified key-value pairs
-
of
public static <K,E> ListMultimap<K,E> of(K k1, E v1, K k2, E v2, K k3, E v3, K k4, E v4, K k5, E v5, K k6, E v6) Creates a new instance of ListMultimap with six key-value pairs.- Type Parameters:
K
- the type of the keysE
- the type of the values- Parameters:
k1
- the first key of the key-value pairsv1
- the first value of the key-value pairsk2
- the second key of the key-value pairsv2
- the second value of the key-value pairsk3
- the third key of the key-value pairsv3
- the third value of the key-value pairsk4
- the fourth key of the key-value pairsv4
- the fourth value of the key-value pairsk5
- the fifth key of the key-value pairsv5
- the fifth value of the key-value pairsk6
- the sixth key of the key-value pairsv6
- the sixth value of the key-value pairs- Returns:
- a new instance of ListMultimap with the specified key-value pairs
-
of
public static <K,E> ListMultimap<K,E> of(K k1, E v1, K k2, E v2, K k3, E v3, K k4, E v4, K k5, E v5, K k6, E v6, K k7, E v7) Creates a new instance of ListMultimap with seven key-value pairs.- Type Parameters:
K
- the type of the keysE
- the type of the values- Parameters:
k1
- the first key of the key-value pairsv1
- the first value of the key-value pairsk2
- the second key of the key-value pairsv2
- the second value of the key-value pairsk3
- the third key of the key-value pairsv3
- the third value of the key-value pairsk4
- the fourth key of the key-value pairsv4
- the fourth value of the key-value pairsk5
- the fifth key of the key-value pairsv5
- the fifth value of the key-value pairsk6
- the sixth key of the key-value pairsv6
- the sixth value of the key-value pairsk7
- the seventh key of the key-value pairsv7
- the seventh value of the key-value pairs- Returns:
- a new instance of ListMultimap with the specified key-value pairs
-
create
Creates a new instance of ListMultimap with the key-value pairs from the specified map.- Type Parameters:
K
- the type of the keysE
- the type of the values- Parameters:
map
- the map containing the key-value pairs to be added to the new ListMultimap- Returns:
- a new instance of ListMultimap with the key-value pairs from the specified map
-
create
public static <T,K> ListMultimap<K,T> create(Collection<? extends T> c, Function<? super T, ? extends K> keyMapper) throws IllegalArgumentExceptionCreates a new instance of ListMultimap from a given collection and a key mapper function.- Type Parameters:
T
- the type of the elements in the collectionK
- the type of the keys in the ListMultimap- Parameters:
c
- the collection of elements to be added to the ListMultimapkeyMapper
- the function to generate keys for the ListMultimap- Returns:
- a new instance of ListMultimap with keys and values from the specified collection
- Throws:
IllegalArgumentException
- if the keyMapper is null
-
create
public static <T,K, ListMultimap<K,E> E> create(Collection<? extends T> c, Function<? super T, ? extends K> keyMapper, Function<? super T, throws IllegalArgumentException? extends E> valueExtractor) Creates a new instance of ListMultimap from a given collection, a key mapper function, and a value extractor function.- Type Parameters:
T
- the type of the elements in the collectionK
- the type of the keys in the ListMultimapE
- the type of the values in the ListMultimap- Parameters:
c
- the collection of elements to be added to the ListMultimapkeyMapper
- the function to generate keys for the ListMultimapvalueExtractor
- the function to extract values for the ListMultimap- Returns:
- a new instance of ListMultimap with keys and values from the specified collection
- Throws:
IllegalArgumentException
- if the keyMapper or valueExtractor is null
-
concat
public static <K,E> ListMultimap<K,E> concat(Map<? extends K, ? extends E> a, Map<? extends K, ? extends E> b) Creates a new instance of ListMultimap by concatenating the key-value pairs from two specified maps.- Type Parameters:
K
- the type of the keysE
- the type of the values- Parameters:
a
- the first map containing the key-value pairs to be added to the new ListMultimapb
- the second map containing the key-value pairs to be added to the new ListMultimap- Returns:
- a new instance of ListMultimap with the key-value pairs from the specified maps
-
concat
public static <K,E> ListMultimap<K,E> concat(Map<? extends K, ? extends E> a, Map<? extends K, ? extends E> b, Map<? extends K, ? extends E> c) Creates a new instance of ListMultimap by concatenating the key-value pairs from three specified maps.- Type Parameters:
K
- the type of the keysE
- the type of the values- Parameters:
a
- the first map containing the key-value pairs to be added to the new ListMultimapb
- the second map containing the key-value pairs to be added to the new ListMultimapc
- the third map containing the key-value pairs to be added to the new ListMultimap- Returns:
- a new instance of ListMultimap with the key-value pairs from the specified maps
-
concat
Creates a new instance of ListMultimap by concatenating the key-value pairs from a collection of maps.- Type Parameters:
K
- the type of the keysE
- the type of the values- Parameters:
c
- the collection of maps containing the key-value pairs to be added to the new ListMultimap- Returns:
- a new instance of ListMultimap with the key-value pairs from the specified collection of maps
-
wrap
@Beta public static <K,E, ListMultimap<K,V extends List<E>> E> wrap(Map<K, V> map) throws IllegalArgumentExceptionWraps the provided map into a ListMultimap. Changes to the specified map will be reflected in the ListMultimap and vice versa.- Type Parameters:
K
- the type of the keys in the mapE
- the type of the elements in the listV
- the type of the list- Parameters:
map
- the map to be wrapped into a ListMultimap- Returns:
- a new instance of ListMultimap backed by the provided map.
- Throws:
IllegalArgumentException
- if the provided map is null
-
wrap
@Beta public static <K,E, ListMultimap<K,V extends List<E>> E> wrap(Map<K, V> map, Supplier<? extends V> valueSupplier) throws IllegalArgumentExceptionWraps the provided map into a ListMultimap with a custom list supplier. Changes to the specified map will be reflected in the ListMultimap and vice versa.- Type Parameters:
K
- the type of the keys in the mapE
- the type of the elements in the listV
- the type of the list- Parameters:
map
- the map to be wrapped into a ListMultimapvalueSupplier
- the supplier that provides the list to be used as the value collection- Returns:
- a new instance of ListMultimap backed by the provided map.
- Throws:
IllegalArgumentException
- if the provided map or valueSupplier is null
-
getFirst
Return the first value for the given key, ornull
if no value is found. -
getFirstOrDefault
Return the first value for the given key, ordefaultValue
if no value is found.- Overrides:
getFirstOrDefault
in classMultimap<K,
E, List<E>> - Parameters:
key
- The key whose associated value is to be returned.defaultValue
- The default value to return if no value is associated with the key.- Returns:
- The first value associated with the specified key, or the default value if the key has no associated values.
-
inverse
Inverts the ListMultimap, swapping keys with values.- Returns:
- a new instance of ListMultimap where the original keys are now values and the original values are now keys
-
copy
Returns a new ListMultimap and copies all key-value pairs from this ListMultimap to the new one. The new ListMultimap has the same structural and hash characteristics as this one. -
filterByKey
Filters the ListMultimap based on the provided key filter. This method creates a new ListMultimap and adds all key-value pairs from the current ListMultimap that satisfy the provided key filter. The new ListMultimap has the same structural and hash characteristics as the current one.- Overrides:
filterByKey
in classMultimap<K,
E, List<E>> - Parameters:
filter
- The predicate to be applied to each key in the ListMultimap. If the predicate returnstrue
, the key-value pair is included in the new ListMultimap.- Returns:
- A new ListMultimap containing all the key-value pairs of the current ListMultimap that satisfy the provided key filter.
-
filterByValue
Filters the ListMultimap based on the provided value filter. This method creates a new ListMultimap and adds all key-value pairs from the current ListMultimap that satisfy the provided value filter. The new ListMultimap has the same structural and hash characteristics as the current one.- Overrides:
filterByValue
in classMultimap<K,
E, List<E>> - Parameters:
filter
- The predicate to be applied to each value in the ListMultimap. If the predicate returnstrue
, the key-value pair is included in the new ListMultimap.- Returns:
- A new ListMultimap containing all the key-value pairs of the current ListMultimap that satisfy the provided value filter.
-
filter
Filters the ListMultimap based on the provided key-value pair filter. This method creates a new ListMultimap and adds all key-value pairs from the current ListMultimap that satisfy the provided key-value pair filter. The new ListMultimap has the same structural and hash characteristics as the current one.- Overrides:
filter
in classMultimap<K,
E, List<E>> - Parameters:
filter
- The predicate to be applied to each key-value pair in the ListMultimap. If the predicate returnstrue
, the key-value pair is included in the new ListMultimap.- Returns:
- A new ListMultimap containing all the key-value pairs of the current ListMultimap that satisfy the provided key-value pair filter.
-
toImmutableMap
Converts the current ListMultimap into an ImmutableMap. Each key-value pair in the ListMultimap is transformed into a key-ImmutableList pair in the ImmutableMap. The ImmutableList contains all the values that were associated with the key in the ListMultimap.- Returns:
- an ImmutableMap where each key is associated with an ImmutableList of values from the original ListMultimap
-
toImmutableMap
public ImmutableMap<K,ImmutableList<E>> toImmutableMap(IntFunction<? extends Map<K, ImmutableList<E>>> mapSupplier) Converts the current ListMultimap into an ImmutableMap using a provided map supplier. Each key-value pair in the ListMultimap is transformed into a key-ImmutableList pair in the ImmutableMap. The ImmutableList contains all the values that were associated with the key in the ListMultimap.- Parameters:
mapSupplier
- The supplier function that provides a Map instance. The function takes an integer argument which is the initial size of the map.- Returns:
- an ImmutableMap where each key is associated with an ImmutableList of values from the original ListMultimap
-