Package org.eclipse.jetty.util
Class MultiMap<V>
- java.lang.Object
-
- java.util.AbstractMap<K,V>
-
- java.util.HashMap<String,List<V>>
-
- org.eclipse.jetty.util.MultiMap<V>
-
- Type Parameters:
V- the entry type for multimap values
- All Implemented Interfaces:
Serializable,Cloneable,Map<String,List<V>>
- Direct Known Subclasses:
UrlEncoded
public class MultiMap<V> extends HashMap<String,List<V>>
A multi valued Map.- See Also:
- Serialized Form
-
-
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>
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(String name, V value)Add value to multi valued entry.booleanaddAllValues(MultiMap<V> map)Merge values.voidaddValues(String name, List<V> values)Add values to multi valued entry.voidaddValues(String name, V[] values)Add values to multi valued entry.booleancontainsSimpleValue(V value)Test for a specific single value in the map.StringgetString(String name)Get value as String.VgetValue(String name, int i)Get a value from a multiple value.List<V>getValues(String name)Get multiple values.List<V>put(String name, V value)Put multi valued entry.voidputAllValues(Map<String,V> input)Shorthand version of putAllList<V>putValues(String name, List<V> values)Put multi valued entry.List<V>putValues(String name, V... values)Put multi valued entry.booleanremoveValue(String name, V value)Remove value.StringtoString()Map<String,String[]>toStringArrayMap()-
Methods inherited from class java.util.HashMap
clear, clone, compute, computeIfAbsent, computeIfPresent, containsKey, containsValue, entrySet, forEach, get, getOrDefault, isEmpty, keySet, merge, put, putAll, putIfAbsent, remove, remove, replace, replace, replaceAll, size, values
-
Methods inherited from class java.util.AbstractMap
equals, hashCode
-
-
-
-
Method Detail
-
getValues
public List<V> getValues(String name)
Get multiple values. Single valued entries are converted to singleton lists.- Parameters:
name- The entry key.- Returns:
- Unmodifieable List of values.
-
getValue
public V getValue(String name, int i)
Get a value from a multiple value. If the value is not a multivalue, then index 0 retrieves the value or null.- Parameters:
name- The entry key.i- Index of element to get.- Returns:
- Unmodifieable List of values.
-
getString
public String getString(String name)
Get value as String. Single valued items are converted to a String with the toString() Object method. Multi valued entries are converted to a comma separated List. No quoting of commas within values is performed.- Parameters:
name- The entry key.- Returns:
- String value.
-
put
public List<V> put(String name, V value)
Put multi valued entry.- Parameters:
name- The entry key.value- The simple value- Returns:
- The previous value or null.
-
putAllValues
public void putAllValues(Map<String,V> input)
Shorthand version of putAll- Parameters:
input- the input map
-
putValues
public List<V> putValues(String name, List<V> values)
Put multi valued entry.- Parameters:
name- The entry key.values- The List of multiple values.- Returns:
- The previous value or null.
-
putValues
@SafeVarargs public final List<V> putValues(String name, V... values)
Put multi valued entry.- Parameters:
name- The entry key.values- The array of multiple values.- Returns:
- The previous value or null.
-
add
public void add(String name, V value)
Add value to multi valued entry. If the entry is single valued, it is converted to the first value of a multi valued entry.- Parameters:
name- The entry key.value- The entry value.
-
addValues
public void addValues(String name, List<V> values)
Add values to multi valued entry. If the entry is single valued, it is converted to the first value of a multi valued entry.- Parameters:
name- The entry key.values- The List of multiple values.
-
addValues
public void addValues(String name, V[] values)
Add values to multi valued entry. If the entry is single valued, it is converted to the first value of a multi valued entry.- Parameters:
name- The entry key.values- The String array of multiple values.
-
addAllValues
public boolean addAllValues(MultiMap<V> map)
Merge values.- Parameters:
map- the map to overlay on top of this one, merging together values if needed.- Returns:
- true if an existing key was merged with potentially new values, false if either no change was made, or there were only new keys.
-
removeValue
public boolean removeValue(String name, V value)
Remove value.- Parameters:
name- The entry key.value- The entry value.- Returns:
- true if it was removed.
-
containsSimpleValue
public boolean containsSimpleValue(V value)
Test for a specific single value in the map.NOTE: This is a SLOW operation, and is actively discouraged.
- Parameters:
value- the value to search for- Returns:
- true if contains simple value
-
-