Class MultiValueMap
- java.lang.Object
-
- co.arago.hiro.client.util.httpclient.MultiValueMap
-
- Direct Known Subclasses:
HttpHeaderMap,URIEncodedData
public class MultiValueMap extends java.lang.ObjectA special map that contains a string as key and a list of string as value. Will not contain null values. This map is used for multi-value-maps like http headers and uri query parameters.
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Map<java.lang.String,java.util.List<java.lang.String>>map
-
Constructor Summary
Constructors Constructor Description MultiValueMap()Constructor without data.MultiValueMap(MultiValueMap other)MultiValueMap(java.util.Map<java.lang.String,?> initialValues)Constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidappend(java.lang.String key, java.lang.String value)Add a single value into the map or remove it.voidappend(java.lang.String key, java.util.Collection<java.lang.String> values)Add a multiple values into the map or remove it.voidappendAll(MultiValueMap other)Add values.voidappendAll(java.util.Map<java.lang.String,?> values)Add values.booleanequals(java.lang.Object o)java.util.List<java.lang.String>getAll(java.lang.String key)Obtain all values for a key.java.util.List<java.lang.String>getAllIgnoreCase(java.lang.String key)Obtain all values for a key.java.lang.StringgetFirst(java.lang.String key)Obtain the first value for a key.java.lang.StringgetFirstIgnoreCase(java.lang.String key)Obtain the first value for a key.java.util.Map<java.lang.String,java.util.List<java.lang.String>>getMapCopy()inthashCode()voidset(java.lang.String key, java.lang.String value)Put a single value into the map or remove it.voidset(java.lang.String key, java.util.Collection<java.lang.String> values)Put a list of values into the map or remove it.voidsetAll(MultiValueMap other)Clear map and set values.voidsetAll(java.util.Map<java.lang.String,?> initialValues)Clear map and set values.java.util.Map<java.lang.String,java.lang.String>toSingleValueMap()
-
-
-
Constructor Detail
-
MultiValueMap
public MultiValueMap()
Constructor without data.
-
MultiValueMap
public MultiValueMap(java.util.Map<java.lang.String,?> initialValues)
Constructor- Parameters:
initialValues- A map of initial values. The values need to be either String or Collection<String>.
-
MultiValueMap
public MultiValueMap(MultiValueMap other)
-
-
Method Detail
-
setAll
public void setAll(java.util.Map<java.lang.String,?> initialValues)
Clear map and set values.- Parameters:
initialValues- A map of initial values. The values need to be either String or Collection<String>. If this is null, the map will be just cleared. ATTENTION: If a key with a value == null is encountered, all values under this key will be removed.
-
setAll
public void setAll(MultiValueMap other)
Clear map and set values.- Parameters:
other- Data will be copied over from here. If this is null, the map will be just cleared.
-
set
public void set(java.lang.String key, java.lang.String value)Put a single value into the map or remove it.- Parameters:
key- The key for the value. Overwrites all previous values of that key.value- The value itself. ATTENTION: If this is null, the key and its values will be removed from the map.
-
set
public void set(java.lang.String key, java.util.Collection<java.lang.String> values)Put a list of values into the map or remove it.- Parameters:
key- The key for the values. Overwrites all previous values of that key.values- The values themselves. ATTENTION: If this is null, the key and its values will be removed from the map.
-
appendAll
public void appendAll(MultiValueMap other)
Add values. These will be appended to the lists of existing values if possible.- Parameters:
other- Data will be copied over from here.
-
appendAll
public void appendAll(java.util.Map<java.lang.String,?> values)
Add values. These will be appended to the lists of existing values if possible.- Parameters:
values- A map of values. The values need to be either String or Collection<String>. ATTENTION: If a key with a value == null is encountered, all values under this key will be removed.
-
append
public void append(java.lang.String key, java.lang.String value)Add a single value into the map or remove it.- Parameters:
key- The key for the value. If the key already has values, the value is appended.value- The value itself. ATTENTION: If this is null, the key and its values will be removed from the map.
-
append
public void append(java.lang.String key, java.util.Collection<java.lang.String> values)Add a multiple values into the map or remove it.- Parameters:
key- The key for the values. If the key already has values, the values are appended.values- The values themselves. ATTENTION: If this is null, the key and its values will be removed from the map.
-
getFirst
public java.lang.String getFirst(java.lang.String key)
Obtain the first value for a key.- Parameters:
key- Key for a value.- Returns:
- The first value found.
-
getFirstIgnoreCase
public java.lang.String getFirstIgnoreCase(java.lang.String key)
Obtain the first value for a key. Ignore case of key.- Parameters:
key- Key for a value.- Returns:
- The first value found.
-
getAll
public java.util.List<java.lang.String> getAll(java.lang.String key)
Obtain all values for a key.- Parameters:
key- Key for a value list.- Returns:
- List of all values under that key.
-
getAllIgnoreCase
public java.util.List<java.lang.String> getAllIgnoreCase(java.lang.String key)
Obtain all values for a key. Ignore case of key.- Parameters:
key- Key for a value list.- Returns:
- List of all values under that key.
-
equals
public boolean equals(java.lang.Object o)
- Overrides:
equalsin classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCodein classjava.lang.Object
-
getMapCopy
public java.util.Map<java.lang.String,java.util.List<java.lang.String>> getMapCopy()
- Returns:
- A deep copy of the internal map.
-
toSingleValueMap
public java.util.Map<java.lang.String,java.lang.String> toSingleValueMap()
- Returns:
- Create a map with keys and only the first value of the arrays behind those keys.
-
-