public class MapUtils extends Object
Constructor and Description |
---|
MapUtils() |
Modifier and Type | Method and Description |
---|---|
static <K,V> Map<K,V> |
asMap(K key1,
V value1,
Object... theRest)
Creates a typed
Map including the provided content, treating it as a sequence of key-value pairs. |
static Map<String,String> |
asStringMap(String... content)
Creates a
Map including the provided String content, treating it as a sequence of key-value pairs |
static <K,V> Map<K,V> |
cloneMap(Map<K,V> originalMap)
Creates a clone of a given
Map . |
static List<StringPair> |
toListOfStringPairs(Map<String,?> sourceMap) |
static List<StringTrio> |
toListOfStringTrios(Map<String,Map<String,?>> sourceMap) |
static <T> Map<String,List<T>> |
toMapOfListType(Map<String,? extends List<?>> map,
Class<T> type)
|
static <T> Map<String,T> |
toMapOfType(Map<String,?> map,
Class<T> type)
|
static Map<String,List<String>> |
toStringListMap(Map<String,? extends List<?>> map)
|
static Map<String,String> |
toStringValuedMap(Map<String,?> map)
|
public static <T> Map<String,T> toMapOfType(Map<String,?> map, Class<T> type)
T
- the type of the values in the resulting mapmap
- the map with String
keystype
- the class of the type of the resulting map valuesString
keys and type
valuesIllegalArgumentException
- if the any of the values in the map cannot be converted to the given typepublic static Map<String,List<String>> toStringListMap(Map<String,? extends List<?>> map)
public static <T> Map<String,List<T>> toMapOfListType(Map<String,? extends List<?>> map, Class<T> type)
String
keys and List
values, to a map with String
keys and List
of given type of valuesT
- the type of the resulting values in the List
values in the Map
map
- the map with String
keys and List
valuestype
- the class of the type that the resulting values in the List
values of the Map
String
keys and List
of given type of valuesIllegalArgumentException
- if the any of the objects in any of the lists in the map cannot be converted to
the given typepublic static List<StringPair> toListOfStringPairs(Map<String,?> sourceMap)
public static List<StringTrio> toListOfStringTrios(Map<String,Map<String,?>> sourceMap)
public static <K,V> Map<K,V> cloneMap(Map<K,V> originalMap)
Map
. The original and cloned maps will refer separate objects for Java
immutable entries (keys or values) while both will refer the same objects for mutable objects.K
- the type of the entry keysV
- the type of the entry valuesoriginalMap
- the map to be clonedMap
with the contents of the original map, or empty map if the original map is nullpublic static Map<String,String> asStringMap(String... content)
Map
including the provided String
content, treating it as a sequence of key-value pairscontent
- the content to be included in the map, in the form key1, value1, key2, value2, ...
Map
including the provided content as key-value pairspublic static <K,V> Map<K,V> asMap(K key1, V value1, Object... theRest)
Map
including the provided content, treating it as a sequence of key-value pairs.
Key and value types of the map would be determined using the first two parameters. Please note that this method
does not perform type validation for the rest of the content (included in theRest
.K
- the key type for the map (determined using key1
V
- the value type for the map (determined using value1
key1
- the first key to be included in the map; decides the key type of the mapvalue1
- the first value to be included in the map; decides the value type of the maptheRest
- rest of the content to be included in the map, in the form key2, value3, key3, value3, ...
Map
including the provided content as key-value pairsCopyright © 2016–2019 AdroitLogic. All rights reserved.