Class MultiHashMap<K,V>
java.lang.Object
- Type Parameters:
K- the type of keys maintained by this mapV- the type of the values stored per key
- All Implemented Interfaces:
Serializable, Cloneable, Map<K, ArrayList<V>>, SequencedMap<K, ArrayList<V>>
A map that can hold several values per key. Each key is mapped to an
ArrayList of values; the keys keep their
insertion order (based on LinkedHashMap). Use putEntry(Object, Object) and
removeEntry(Object, Object) to add or remove single values.
Note: size() is overridden and returns the total number of values, not the number of keys. The class is not
synchronized.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionbooleancontainsValue(Object value) Checks whether a single value is stored under any key (not whether a value list is stored).intkeysSize()Intended to return the number of keys.Adds a value to the list of a key; the list is created if necessary.voidremoveEntry(K key, V value) Removes a value from the list of a key.intsize()Returns the total number of values over all keys (not the number of keys).intMethods inherited from class LinkedHashMap
clear, entrySet, forEach, get, getOrDefault, keySet, newLinkedHashMap, putFirst, putLast, removeEldestEntry, replaceAll, reversed, sequencedEntrySet, sequencedKeySet, sequencedValues, valuesMethods inherited from class HashMap
clone, compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, newHashMap, put, putAll, putIfAbsent, remove, remove, replace, replaceMethods inherited from class AbstractMap
equals, hashCode, toStringMethods inherited from interface Map
compute, computeIfAbsent, computeIfPresent, containsKey, equals, hashCode, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replaceMethods inherited from interface SequencedMap
firstEntry, lastEntry, pollFirstEntry, pollLastEntry
-
Constructor Details
-
MultiHashMap
public MultiHashMap()
-
-
Method Details
-
keysSize
public int keysSize()Intended to return the number of keys. Note: becausesize()is overridden, this currently returns the total number of values as well.- Returns:
- the number of values (see note)
-
valueSize
public int valueSize()- Returns:
- the total number of values over all keys
-
size
-
containsValue
Checks whether a single value is stored under any key (not whether a value list is stored).- Specified by:
containsValuein interfaceMap<K,V> - Overrides:
containsValuein classLinkedHashMap<K, ArrayList<V>>
-
allValues
- Returns:
- a new collection with the values of all keys, in key order
-
putEntry
-
removeEntry
-