Package org.kiwiproject.jaxrs
Class KiwiMultivaluedMaps
java.lang.Object
org.kiwiproject.jaxrs.KiwiMultivaluedMaps
Static utilities for working with
MultivaluedMap instances.-
Method Summary
Modifier and TypeMethodDescriptionnewMultivaluedMap(String... items) Create a newMultivaluedMapfrom the given items, which are expected to be in alternating key/value pairs.newSingleValuedParameterMap(String... items) Create a newMultivaluedMapfrom the given items, which are expected to be in alternating key/value pairs.toMultimap(jakarta.ws.rs.core.MultivaluedMap<String, String> original) Convert the givenMultivaluedMapinto a GuavaMultimap.toSingleValuedParameterMap(jakarta.ws.rs.core.MultivaluedMap<String, String> original) Converts the givenMultivaluedMapto a single-valued JDKMapby getting only the first element for each key in the multivalued map.
-
Method Details
-
newMultivaluedMap
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 jakarta.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(jakarta.ws.rs.core.MultivaluedMap<String, String> original) Converts the givenMultivaluedMapto a single-valued JDKMapby getting only the first element for each key in the multivalued map. This means that if there are keys having multiple values, elements past the first one are ignored.- Parameters:
original- the original multivalued map to convert- Returns:
- the single-valued JDK map
-
toMultimap
public static com.google.common.collect.Multimap<String,String> toMultimap(jakarta.ws.rs.core.MultivaluedMap<String, String> original) Convert the givenMultivaluedMapinto a GuavaMultimap.- Parameters:
original- the original multivalued map to convert- Returns:
- the Guava multimap
-