public class MultiValueMap<K,V> extends Object implements Map<K,List<V>>
While manipulating only first values or only duplicates is efficient, the value retrieval and replacing values of across first value through to the duplicates is not efficient as the other operations. However the key set retrieval is still efficient.
Constructor and Description |
---|
MultiValueMap() |
MultiValueMap(Map<K,V> firstValues,
Map<K,List<V>> duplicates)
|
MultiValueMap(MultiValueMap<K,V> multiValueMap)
This will create a new
MultiValueMap instance with all the values of the multiValueMap . |
Modifier and Type | Method and Description |
---|---|
void |
add(K key,
V value)
Adds a new value with the given value for the given key
|
void |
clear() |
boolean |
containsFirstValue(Object value)
Checks whether the given value is there in the first values.
|
boolean |
containsKey(Object key) |
boolean |
containsValue(Object value)
Checks whether the given value is in either the first values or in any duplicates as well
|
boolean |
containsValueInDuplicates(Object value)
Checks whether the value is in duplicates excluding the first values
|
Set<Map.Entry<K,List<V>>> |
entrySet() |
List<V> |
get(Object key)
This method is not efficient, if you just need the first value use
getFirst(K) instead |
List<V> |
getDuplicates(K key)
Retrieves the only duplicates if there are any as a list of values for the given key
|
V |
getFirst(K key)
Retrieves the first value of the multi value map for the given key
|
Map<K,List<V>> |
getOnlyDuplicates()
Gives the duplicates only excluding the first values map, for entries without duplicates will be
excluded from this map
|
Map<K,V> |
getSingleValueMap()
Gives the complete single value map view of the map
|
boolean |
isEmpty() |
Set<K> |
keySet() |
List<V> |
put(K key,
List<V> value) |
void |
putAll(Map<? extends K,? extends List<V>> m) |
List<V> |
remove(Object key) |
int |
size() |
Collection<List<V>> |
values() |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
compute, computeIfAbsent, computeIfPresent, equals, forEach, getOrDefault, hashCode, merge, putIfAbsent, remove, replace, replace, replaceAll
public MultiValueMap()
public MultiValueMap(MultiValueMap<K,V> multiValueMap)
MultiValueMap
instance with all the values of the multiValueMap
.
The two MultiValueMaps will refer separate objects for any Java immutable objects while both will refer the same
objects for others.multiValueMap
- original MultiValueMap
to be copied into this new onepublic MultiValueMap(Map<K,V> firstValues, Map<K,List<V>> duplicates)
MultiValueMap
instance with the values of the firstValues
and
duplicates
. The newly created MultiValueMap will refer separate objects for any Java immutable objects
and will refer the same objects for others.firstValues
- Map to be copied as first valuesduplicates
- Map to be copied as duplicatespublic boolean containsKey(Object key)
containsKey
in interface Map<K,List<V>>
public boolean containsValue(Object value)
containsValue
in interface Map<K,List<V>>
value
- the value to be searched for existencepublic boolean containsFirstValue(Object value)
value
- the value to be searched for existence in first valuespublic boolean containsValueInDuplicates(Object value)
value
- the value to be searched for the existencepublic List<V> get(Object key)
getFirst(K)
insteadpublic V getFirst(K key)
key
- the key to fetch the first valuepublic List<V> getDuplicates(K key)
key
- the key to fetch the duplicatespublic void add(K key, V value)
key
- the key to add the new valuevalue
- the new value to be addedpublic Map<K,V> getSingleValueMap()
public Map<K,List<V>> getOnlyDuplicates()
Copyright © 2016–2019 AdroitLogic. All rights reserved.