Package com.tccc.kos.commons.util
Class MultiValueMap<K,V> 
java.lang.Object
com.tccc.kos.commons.util.MultiValueMap<K,V> 
Specialized class that behaves like a map of lists,
 which means that each key can hold multiple values.
 
Usage
The constructor takes two generic parameters, K and V.- "K" is the type used as the map's key
- "V" is the data type stored in the value's list
new MultiValueMap<Integer, String>()while:
new MultiValueMap<String, Object>()Example
 
  public class MyClass {
      private MultiValueMap<Integer, String> multiValueMap = new MultiValueMap<>();
      multiValueMap.set("key1", "value1");
      multiValueMap.add("key1", "value2");
      multiValueMap.add("key1", "value3");
      multiValueMap.remove("key1", "value2");
      List<String> key1List = multiValueMap.get("key1");
      assertThat(key1List, equalTo(List.of("value1", "value3"));
  }
 
 - Since:
- 1.0
- Version:
- 2022-10-26
- 
Constructor SummaryConstructors
- 
Method SummaryModifier and TypeMethodDescriptionvoidAdds the given value to the list of items associated with the given key.voidAdds the contents of the given map into this object's internal map.voidaddAll(K key, Collection<V> values) Adds the contents of the given list to the list associated with the specified key.voidAdd the specified key to the map with an empty list if the key doesn't already exist.voidclear()Removes all items from this map.booleanReturn true if the specified value is contained in the list associated with the key.booleancontainsKey(Object key) Determines if the map contains the given key or not.entrySet()Returns a set of all map entries.Returns the list of values for the specified key.Returns the first value of the specified key.Returns the last value of the specified key.booleanisEmpty()Determines if the map is empty or not.keySet()Returns a set of this map's key set.Removes the map entry for the specified key.voidRemoves the specified value from the list associated with the given map.voidSets the given key to a list containing one item, which is the given value.voidCopies the contents of the given map into this object's internal map.intsize()Returns the number of items in the map.Collection<List<V>>values()Returns a collection of lists for all items in the map.
- 
Constructor Details- 
MultiValueMappublic MultiValueMap()Constructs an empty multi-value map.
 
- 
- 
Method Details- 
sizepublic int size()Returns the number of items in the map.- Returns:
- number of items in the map
 
- 
isEmptypublic boolean isEmpty()Determines if the map is empty or not.- Returns:
- trueif this map is empty, otherwise- false
 
- 
addKeyAdd the specified key to the map with an empty list if the key doesn't already exist.- Parameters:
- key- the key to add if needed
 
- 
containsKeyDetermines if the map contains the given key or not.- Parameters:
- key- the key to check for existence
- Returns:
- trueif this map contains an entry for the given key
 
- 
containsReturn true if the specified value is contained in the list associated with the key.- Parameters:
- key- the key to check
- val- the value to check
 
- 
getFirstReturns the first value of the specified key.- Parameters:
- key- the key to return a value for
- Returns:
- the first value for the key
 
- 
getLastReturns the last value of the specified key.- Parameters:
- key- the key to return a value for
- Returns:
- the last value for the key
 
- 
getReturns the list of values for the specified key.- Parameters:
- key- the key to return the list for
- Returns:
- a Listof values, or empty list if there are none
 
- 
setSets the given key to a list containing one item, which is the given value.- Parameters:
- key- the key for the map
- value- the value put in the associated list
 
- 
setAllCopies the contents of the given map into this object's internal map.- Parameters:
- map- the source map that gets copied
 
- 
addAdds the given value to the list of items associated with the given key.- Parameters:
- key- the key for the map
- value- the value to add to the associated list
 
- 
addAllAdds the contents of the given map into this object's internal map.- Parameters:
- map- the source map that gets added
 
- 
addAllAdds the contents of the given list to the list associated with the specified key.- Parameters:
- key- the key to add values to
- values- the list to add
 
- 
removeRemoves the map entry for the specified key.- Parameters:
- key- the key of the map
- Returns:
- the list of items removed, or nullif key did not exist
 
- 
removeRemoves the specified value from the list associated with the given map.- Parameters:
- key- the key of the map
- value- the value in the associated list to remove
 
- 
clearpublic void clear()Removes all items from this map.
- 
keySetReturns a set of this map's key set.- Returns:
- set of all keys
 
- 
valuesReturns a collection of lists for all items in the map.- Returns:
- collection of all lists
 
- 
entrySetReturns a set of all map entries.- Returns:
- set of all map entries
 
 
-