Package io.github.connellite.collections
Class LinkedMultiValueHashMap<K,V>
java.lang.Object
java.util.AbstractMap<K,V>
java.util.HashMap<K,V>
java.util.LinkedHashMap<K,List<V>>
io.github.connellite.collections.LinkedMultiValueHashMap<K,V>
- Type Parameters:
K- the key typeV- the value element type
- All Implemented Interfaces:
MultiValueMap<K,,V> Serializable,Cloneable,Map<K,List<V>>
public class LinkedMultiValueHashMap<K,V>
extends LinkedHashMap<K,List<V>>
implements MultiValueMap<K,V>, Serializable, Cloneable
Simple implementation of
MultiValueMap that wraps a LinkedHashMap,
storing multiple values in an ArrayList.
This Map implementation is generally not thread-safe. It is primarily designed for data structures exposed from request objects, for use in a single thread only.
- See Also:
-
Nested Class Summary
Nested classes/interfaces inherited from class java.util.AbstractMap
AbstractMap.SimpleEntry<K extends Object,V extends Object>, AbstractMap.SimpleImmutableEntry<K extends Object, V extends Object> -
Constructor Summary
ConstructorsConstructorDescriptionCreate a newLinkedMultiValueHashMapthat wraps aLinkedHashMap.LinkedMultiValueHashMap(int expectedSize) Create a newLinkedMultiValueHashMapthat wraps aLinkedHashMapwith the given initial capacity.LinkedMultiValueHashMap(MultiValueMap<K, V> otherMap) Copy constructor: Create a newLinkedMultiValueHashMapwith the same mappings as the specifiedMultiValueMap.LinkedMultiValueHashMap(Map<K, List<V>> otherMap) Copy constructor: Create a newLinkedMultiValueHashMapwith the same mappings as the specified Map. -
Method Summary
Modifier and TypeMethodDescriptionvoidAdd the given single value to the current list of values for the given key.voidaddAll(MultiValueMap<K, V> values) Add all the values of the givenMultiValueMapto the current values.voidAdd all the values of the given list to the current list of values for the given key.clone()deepCopy()Create a deep copy of this Map.Return the first value for the given key.voidSet the given single value under the given key.voidSet the given values under their associated key.Return aMapwith the first values contained in thisMultiValueMap.Return an unmodifiable view of this map with immutable value lists.Methods inherited from class java.util.LinkedHashMap
clear, containsValue, entrySet, forEach, get, getOrDefault, keySet, removeEldestEntry, replaceAll, valuesMethods inherited from class java.util.HashMap
compute, computeIfAbsent, computeIfPresent, containsKey, isEmpty, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, sizeMethods inherited from class java.util.AbstractMap
equals, hashCode, toStringMethods inherited from class java.lang.Object
finalize, getClass, notify, notifyAll, wait, wait, waitMethods inherited from interface java.util.Map
clear, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, equals, forEach, get, getOrDefault, hashCode, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, valuesMethods inherited from interface io.github.connellite.collections.MultiValueMap
addIfAbsent
-
Constructor Details
-
LinkedMultiValueHashMap
public LinkedMultiValueHashMap()Create a newLinkedMultiValueHashMapthat wraps aLinkedHashMap. -
LinkedMultiValueHashMap
public LinkedMultiValueHashMap(int expectedSize) Create a newLinkedMultiValueHashMapthat wraps aLinkedHashMapwith the given initial capacity.- Parameters:
expectedSize- the expected number of entries
-
LinkedMultiValueHashMap
Copy constructor: Create a newLinkedMultiValueHashMapwith the same mappings as the specified Map.- Parameters:
otherMap- the Map whose mappings are to be placed in this Map
-
LinkedMultiValueHashMap
Copy constructor: Create a newLinkedMultiValueHashMapwith the same mappings as the specifiedMultiValueMap.- Parameters:
otherMap- the Map whose mappings are to be placed in this Map
-
-
Method Details
-
getFirst
Description copied from interface:MultiValueMapReturn the first value for the given key.- Specified by:
getFirstin interfaceMultiValueMap<K,V> - Parameters:
key- the key- Returns:
- the first value for the specified key, or
null
-
add
Description copied from interface:MultiValueMapAdd the given single value to the current list of values for the given key.- Specified by:
addin interfaceMultiValueMap<K,V> - Parameters:
key- the keyvalue- the value to be added
-
addAll
Description copied from interface:MultiValueMapAdd all the values of the given list to the current list of values for the given key.- Specified by:
addAllin interfaceMultiValueMap<K,V> - Parameters:
key- they keyvalues- the values to be added
-
addAll
Description copied from interface:MultiValueMapAdd all the values of the givenMultiValueMapto the current values.- Specified by:
addAllin interfaceMultiValueMap<K,V> - Parameters:
values- the values to be added
-
set
Description copied from interface:MultiValueMapSet the given single value under the given key.- Specified by:
setin interfaceMultiValueMap<K,V> - Parameters:
key- the keyvalue- the value to set
-
setAll
Description copied from interface:MultiValueMapSet the given values under their associated key.- Specified by:
setAllin interfaceMultiValueMap<K,V> - Parameters:
values- the values
-
toSingleValueMap
Description copied from interface:MultiValueMapReturn aMapwith the first values contained in thisMultiValueMap.- Specified by:
toSingleValueMapin interfaceMultiValueMap<K,V> - Returns:
- a single value representation of this map
-
toUnmodifiableMap
Description copied from interface:MultiValueMapReturn an unmodifiable view of this map with immutable value lists. The returned map and its list values cannot be modified; changes to this map are not reflected in the returned instance.- Specified by:
toUnmodifiableMapin interfaceMultiValueMap<K,V> - Returns:
- unmodifiable map with copied value lists
-
deepCopy
Create a deep copy of this Map.- Returns:
- a copy of this Map, including a copy of each value-holding List entry
-
clone
-