Package com.yetnt.utils.collection
Class HashMultiMap<K,T>
java.lang.Object
java.util.AbstractMap<K,ArrayList<T>>
java.util.HashMap<K,ArrayList<T>>
com.yetnt.utils.collection.HashMultiMap<K,T>
- Type Parameters:
K- the type of keys maintained by this multimapT- the type stored in the list
- All Implemented Interfaces:
Serializable,Cloneable,Map<K,ArrayList<T>>
A HashMap who maps 1 key to multiple values.
This class provides methods like putValue(Object, Object) to add a single value to the collection of values
associated with a key, and getValues(Object) to retrieve all values for a given key.
- Author:
- Lehlogonolo Poole
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K,V>, AbstractMap.SimpleImmutableEntry<K, V> -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionfindFirstKeyWhere(Predicate<ArrayList<T>> test) Retrieves the list of values associated with the specified key.booleanvoidAdds a value to the list of values associated with the specified key.Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, newHashMap, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from class java.util.AbstractMap
equals, hashCode, toString
-
Constructor Details
-
HashMultiMap
public HashMultiMap()
-
-
Method Details
-
putValue
Adds a value to the list of values associated with the specified key. If the key does not already exist in the map, a new list is created for it.- Parameters:
key- The key to which the value should be added.value- The value to add to the list associated with the key.
-
getValues
Retrieves the list of values associated with the specified key.- Parameters:
key- The key whose associated values are to be returned.- Returns:
- The list of values associated with the specified key, or
nullif the key does not exist in the map.
-
holdsSingletonLists
public boolean holdsSingletonLists() -
findFirstKeyWhere
-