Java Utililty Methods Map Merge

List of utility methods to do Map Merge

Description

The list of methods to do Map Merge are organized into topic(s).

Method

voidmergeBootArgumentsIntoMap(String[] args, Map map)
merge Boot Arguments Into Map
if (map == null) {
    throw new IllegalArgumentException("Map must not be null");
for (String arg : args) {
    if (arg.startsWith("--") && arg.length() > 4) {
        String[] split = arg.substring(2).split("=");
        if (split.length == 2) {
            map.put(split[0], split[1]);
...
voidmergeCompactedValue(Map obj, String key, Object value)
merge Compacted Value
if (obj == null) {
    return;
final Object prop = obj.get(key);
if (prop == null) {
    obj.put(key, value);
    return;
if (!(prop instanceof List)) {
    final List<Object> tmp = new ArrayList<Object>();
    tmp.add(prop);
if (value instanceof List) {
    ((List<Object>) prop).addAll((List<Object>) value);
} else {
    ((List<Object>) prop).add(value);
MapmergeCompositions(Map target, Map source)
merge Compositions
if (source == null || target == null) {
    return target;
for (String key : source.keySet()) {
    Integer value = target.get(key);
    if (value == null) {
        target.put(key, source.get(key));
    else {
        target.put(key, value + source.get(key));
return target;
MapmergeConfig(Map userConfig, Map referenceConfig)
Produce a map where the reference values are overridden with user values.
Map<String, Object> config = new HashMap<>(referenceConfig);
config.putAll(userConfig);
return config;
voidmergeCounterMap(Map map, String key, Object value)
merge Counter Map
if (value instanceof Map) {
    mergeCounterMap(map, key, (Map) value);
} else {
    mergeCounterMap(map, key, (Number) value);
voidmergeCountMaps(Map base, Map other)
Merge two count maps of type
for (Entry<K, Integer> entry : other.entrySet()) {
    K key = entry.getKey();
    Integer value = entry.getValue();
    if (base.get(key) == null) {
        base.put(key, value);
    } else {
        base.put(key, base.get(key) + value);
voidmergeCounts(Map counter, String key)
merge Counts
if (counter.containsKey(key)) {
    Integer count = counter.get(key);
    counter.put(key, ++count);
} else {
    counter.put(key, 1);
MapmergeCustomProperties(Map copyTo, Map copyFrom)
merge Custom Properties
if (copyTo == null) {
    return copyFrom;
} else if (copyFrom != null && !copyFrom.isEmpty()) {
    copyTo.putAll(copyFrom);
return copyTo;
voidmergeDefaults(Map content, Map defaults)
Merge defaults.
for (Map.Entry<String, Object> defaultEntry : defaults.entrySet()) {
    if (!content.containsKey(defaultEntry.getKey())) {
        content.put(defaultEntry.getKey(), defaultEntry.getValue());
    } else {
        if (content.get(defaultEntry.getKey()) instanceof Map && defaultEntry.getValue() instanceof Map) {
            mergeDefaults((Map<String, Object>) content.get(defaultEntry.getKey()),
                    (Map<String, Object>) defaultEntry.getValue());
        } else if (content.get(defaultEntry.getKey()) instanceof List
...
MapmergeEntries(Map dest, Iterable> entries)
Merge a set of entries into a map.
for (Map.Entry<String, String> entry : entries) {
    dest.put(entry.getKey(), entry.getValue());
return dest;