Package org.jivesoftware.smack.util
Class MultiMap<K,V>
java.lang.Object
org.jivesoftware.smack.util.MultiMap<K,V>
- Type Parameters:
K
- the type of the keys the map uses.V
- the type of the values the map uses.
A lightweight implementation of a MultiMap, that is a Map that is able to hold multiple values for every key.
This MultiMap uses a LinkedHashMap
together with a ArrayList
in order to keep the order of its entries.
-
Field Summary
-
Constructor Summary
ConstructorDescriptionMultiMap()
Constructs a new MultiMap with a initial capacity ofDEFAULT_MAP_SIZE
.MultiMap
(int size) Constructs a new MultiMap. -
Method Summary
Modifier and TypeMethodDescriptionvoid
clear()
clone()
boolean
containsKey
(K key) boolean
containsValue
(V value) entrySet()
Get all values for the given key.Get the first value for the given key, ornull
if there are no entries.boolean
isEmpty()
keySet()
boolean
void
boolean
Removes all mappings for the given key and returns the first value if there where mappings ornull
if not.Remove the given number of values for a given key.boolean
Remove the mapping of the given key to the value.int
size()
values()
Returns a new list containing all values of this multi map.
-
Field Details
-
DEFAULT_MAP_SIZE
The constant value 6.- See Also:
-
-
Constructor Details
-
MultiMap
public MultiMap()Constructs a new MultiMap with a initial capacity ofDEFAULT_MAP_SIZE
. -
MultiMap
Constructs a new MultiMap.- Parameters:
size
- the initial capacity.
-
-
Method Details
-
size
-
isEmpty
-
containsKey
-
containsValue
-
getFirst
Get the first value for the given key, ornull
if there are no entries.- Parameters:
key
- TODO javadoc me please- Returns:
- the first value or null.
-
getAll
Get all values for the given key. Returns the empty set if there are none.Changes to the returned set will update the underlying MultiMap if the return set is not empty.
- Parameters:
key
- TODO javadoc me please- Returns:
- all values for the given key.
-
put
-
putFirst
-
remove
Removes all mappings for the given key and returns the first value if there where mappings ornull
if not.- Parameters:
key
- TODO javadoc me please- Returns:
- the first value of the given key or null.
-
removeOne
Remove the mapping of the given key to the value.Returns
true
if the mapping was removed andfalse
if the mapping did not exist.- Parameters:
key
- TODO javadoc me pleasevalue
- TODO javadoc me please- Returns:
- true if the mapping was removed, false otherwise.
-
remove
Remove the given number of values for a given key. May return less values than requested.- Parameters:
key
- the key to remove from.num
- the number of values to remove.- Returns:
- a list of the removed values.
- Since:
- 4.4.0
-
putAll
-
clear
-
keySet
-
values
Returns a new list containing all values of this multi map.- Returns:
- a new list with all values.
-
entrySet
-
asUnmodifiableMultiMap
-
clone
-