public class MapUtil extends Object
| Modifier and Type | Method and Description |
|---|---|
static Map<String,Object> |
getFlattenedMap(Map<?,?> source)
Build a flattened representation of provided Map.
|
static Map<String,Object> |
getNestedMap(Map<String,?> flattenedMap)
Build a nested representation of the provided Map.
|
static void |
mergeIfAbsent(Map<String,String> map,
Map<String,String> toMerge)
Add all values of a map to another map, but only if not already existing.
|
static <K,V> Map<K,V> |
mergeMaps(Map<K,V>... maps)
Returns a new map with all the entries of first map with rest map entries which don't override map1.
|
static Map<String,String> |
mergeMaps(Properties... properties)
Returns a new map with all the entries the provided properties merged.
|
static void |
putAllIfNotNull(Map<String,String> ret,
Map<String,String> toPut)
Copies all the elements i.e., the mappings, from toPut map into ret, if toPut isn't null.
|
public static void mergeIfAbsent(Map<String,String> map, Map<String,String> toMerge)
map - target maptoMerge - the values to add@SafeVarargs public static <K,V> Map<K,V> mergeMaps(Map<K,V>... maps)
K - first typeV - second typemaps - var arg for mapspublic static Map<String,String> mergeMaps(Properties... properties)
properties - var arg for propertiespublic static void putAllIfNotNull(Map<String,String> ret, Map<String,String> toPut)
ret - target hash maptoPut - source hash mappublic static Map<String,Object> getFlattenedMap(Map<?,?> source)
The conversion is compliant with the thorntail spring-boot rules.
Given a Map of Maps:
Collections.singletonMap("key", Collections.singletonMap("nested-key", "value"));
It will return a Map with the following structure
Collections.singletonMap("key.nested-key", "value");
source - map of mapspublic static Map<String,Object> getNestedMap(Map<String,?> flattenedMap)
Given a Map with a flat structure, it returns a Map of nested Maps. The original keys are split by the dot
(.) character. For each element, a new Map node is created.
Given the following YAML representation of a Map:
one.two.key: value
one.two.three: other
It will converted to:
one:
two:
key: value
three: other
flattenedMap - map with a flat structureCopyright © 2024. All rights reserved.