Package org.kiwiproject.jaxrs
Class KiwiMultivaluedMaps
- java.lang.Object
-
- org.kiwiproject.jaxrs.KiwiMultivaluedMaps
-
public class KiwiMultivaluedMaps extends Object
Static utilities for working withMultivaluedMapinstances.
-
-
Constructor Summary
Constructors Constructor Description KiwiMultivaluedMaps()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static javax.ws.rs.core.MultivaluedMap<String,String>newMultivaluedMap(String... items)Create a newMultivaluedMapfrom the given items, which are expected to be in alternating key/value pairs.static javax.ws.rs.core.MultivaluedMap<String,String>newSingleValuedParameterMap(String... items)Create a newMultivaluedMapfrom the given items, which are expected to be in alternating key/value pairs.static com.google.common.collect.Multimap<String,String>toMultimap(javax.ws.rs.core.MultivaluedMap<String,String> original)Convert the givenMultivaluedMapinto a GuavaMultimap.static Map<String,String>toSingleValuedParameterMap(javax.ws.rs.core.MultivaluedMap<String,String> original)Converts the givenMultivaluedMapto a single-valued JDKMapby getting only the first element for each key in the multi-valued map.
-
-
-
Method Detail
-
newMultivaluedMap
public static javax.ws.rs.core.MultivaluedMap<String,String> newMultivaluedMap(String... items)
Create a newMultivaluedMapfrom the given items, which are expected to be in alternating key/value pairs. This allows for keys to be repeated, i.e. so that a single key can have multiple values.- Parameters:
items- the keys and values, e.g. key1, value1, key2, value2, ...- Returns:
- a new
MultivaluedMap - Implementation Note:
- the actual type returned is currently a
MultivaluedHashMap
-
newSingleValuedParameterMap
public static javax.ws.rs.core.MultivaluedMap<String,String> newSingleValuedParameterMap(String... items)
Create a newMultivaluedMapfrom the given items, which are expected to be in alternating key/value pairs.NOTE: Unlike
newMultivaluedMap(String...), this method assumes you want only one value per key, even ifitemscontains multiple values per key. In that case, the last value initemsassociated with a given key is the one that "wins" and stays in the returned map.- Parameters:
items- the keys and values, e.g. key1, value1, key2, value2, ...- Returns:
- a new
MultivaluedMap - Implementation Note:
- the actual type returned is currently a
MultivaluedHashMap
-
toSingleValuedParameterMap
public static Map<String,String> toSingleValuedParameterMap(javax.ws.rs.core.MultivaluedMap<String,String> original)
Converts the givenMultivaluedMapto a single-valued JDKMapby getting only the first element for each key in the multi-valued map. This means that if there are keys having multiple values, elements past the first one are ignored.- Parameters:
original- the original multi-valued map to convert- Returns:
- the single-valued JDK map
-
-