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.
public class MultiMap<K,V> extends Object
A lightweight implementation of a MultiMap, that is a Map that is able to hold multiple values for every key.This MultiMap uses a
LinkedHashMaptogether with aArrayListin order to keep the order of its entries.
-
-
Field Summary
Fields Modifier and Type Field Description static intDEFAULT_MAP_SIZEThe constant value 6.
-
Constructor Summary
Constructors Constructor Description MultiMap()Constructs a new MultiMap with a initial capacity ofDEFAULT_MAP_SIZE.MultiMap(int size)Constructs a new MultiMap.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description MultiMap<K,V>asUnmodifiableMultiMap()voidclear()MultiMap<K,V>clone()booleancontainsKey(K key)booleancontainsValue(V value)Set<Map.Entry<K,V>>entrySet()List<V>getAll(K key)Get all values for the given key.VgetFirst(K key)Get the first value for the given key, ornullif there are no entries.booleanisEmpty()Set<K>keySet()booleanput(K key, V value)voidputAll(Map<? extends K,? extends V> map)booleanputFirst(K key, V value)Vremove(K key)Removes all mappings for the given key and returns the first value if there where mappings ornullif not.List<V>remove(K key, int num)Remove the given number of values for a given key.booleanremoveOne(K key, V value)Remove the mapping of the given key to the value.intsize()List<V>values()Returns a new list containing all values of this multi map.
-
-
-
Field Detail
-
DEFAULT_MAP_SIZE
public static final int DEFAULT_MAP_SIZE
The constant value 6.- See Also:
- Constant Field Values
-
-
Constructor Detail
-
MultiMap
public MultiMap()
Constructs a new MultiMap with a initial capacity ofDEFAULT_MAP_SIZE.
-
MultiMap
public MultiMap(int size)
Constructs a new MultiMap.- Parameters:
size- the initial capacity.
-
-
Method Detail
-
size
public int size()
-
isEmpty
public boolean isEmpty()
-
containsKey
public boolean containsKey(K key)
-
containsValue
public boolean containsValue(V value)
-
getFirst
public V getFirst(K key)
Get the first value for the given key, ornullif there are no entries.- Parameters:
key- TODO javadoc me please- Returns:
- the first value or null.
-
getAll
public List<V> getAll(K key)
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.
-
remove
public V remove(K key)
Removes all mappings for the given key and returns the first value if there where mappings ornullif not.- Parameters:
key- TODO javadoc me please- Returns:
- the first value of the given key or null.
-
removeOne
public boolean removeOne(K key, V value)
Remove the mapping of the given key to the value.Returns
trueif the mapping was removed andfalseif 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
public List<V> remove(K key, int num)
Remove the given number of values for a given key. May return less values then 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
-
clear
public void clear()
-
values
public List<V> values()
Returns a new list containing all values of this multi map.- Returns:
- a new list with all values.
-
asUnmodifiableMultiMap
public MultiMap<K,V> asUnmodifiableMultiMap()
-
-