Package discord4j.rest.util
Class Multimap<K,V>
java.lang.Object
discord4j.rest.util.Multimap<K,V>
- Type Parameters:
K
- the key typeV
- the value type
A simple multi-valued map that wraps a
LinkedHashMap
with LinkedList
to store multiple values.
This class is NOT thread-safe.-
Nested Class Summary
-
Constructor Summary
-
Method Summary
Modifier and TypeMethodDescriptionvoid
Add a value to the list of values under the given key.void
Add all values from the givenMultimap
to the current ones.void
addAll
(K key, Collection<? extends V> values) Add multiple values to the list of values under the given key.void
clear()
boolean
containsKey
(Object key) boolean
containsValue
(Object value) deepCopy()
Clone thisMultimap
using a deep copy, including each stored value list.entrySet()
void
forEachElement
(BiConsumer<? super K, ? super V> action) Performs the given action for each element, meaning once per each K-V entry in this Multimap, until all entries have been processed or the action throws an exception.boolean
isEmpty()
keySet()
void
void
Set a value under the given key, replacing any existing single or multiple values.void
Set multiple values under the given key, replacing any existing single or multiple values.int
size()
Collection<List<V>>
values()
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface java.util.Map
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
-
Constructor Details
-
Multimap
public Multimap()Create an empty Multimap. -
Multimap
public Multimap(int initialCapacity) Create an empty Multimap with a given initial capacity.- Parameters:
initialCapacity
- the initial capacity
-
-
Method Details
-
add
Add a value to the list of values under the given key.- Parameters:
key
- the keyvalue
- the value to add
-
addAll
Add multiple values to the list of values under the given key.- Parameters:
key
- the keyvalues
- the values to add
-
addAll
Add all values from the givenMultimap
to the current ones.- Parameters:
values
- the values to add
-
set
Set a value under the given key, replacing any existing single or multiple values.- Parameters:
key
- the keyvalue
- the value to set
-
setAll
Set multiple values under the given key, replacing any existing single or multiple values.- Parameters:
values
- the values to set
-
deepCopy
Clone thisMultimap
using a deep copy, including each stored value list.- Returns:
- a deep copy of this
Multimap
-
forEachElement
Performs the given action for each element, meaning once per each K-V entry in this Multimap, until all entries have been processed or the action throws an exception.- Parameters:
action
- The action to be performed for each entry- Throws:
NullPointerException
- if the specified action is nullConcurrentModificationException
- if an entry is found to be removed during iteration- Since:
- 3.1.1
-
size
public int size() -
isEmpty
public boolean isEmpty() -
containsKey
- Specified by:
containsKey
in interfaceMap<K,
V>
-
containsValue
- Specified by:
containsValue
in interfaceMap<K,
V>
-
get
-
put
-
remove
-
putAll
-
clear
public void clear() -
keySet
-
values
-
entrySet
-