List of utility methods to do Map Merge
Map | deepMerge(Map dst, Map src) Deep merges two maps if (dst != null && src != null) { for (Object key : src.keySet()) { if (src.get(key) instanceof Map && dst.get(key) instanceof Map) { Map originalChild = (Map) dst.get(key); Map newChild = (Map) src.get(key); dst.put(key, deepMerge(originalChild, newChild)); } else { dst.put(key, src.get(key)); ... |
void | deepMerge(Map Perform a deep merge of two maps. for (K k : m2.keySet()) { V v1 = m1.get(k); V v2 = m2.get(k); if (v1 instanceof Collection && v2 instanceof Collection) { if (((Collection<Object>) v1).containsAll((Collection<Object>) v2)) { } else { ((Collection<Object>) v1).addAll((Collection<Object>) v2); } else if (v1 instanceof Map && v2 instanceof Map) { deepMerge((Map<Object, Object>) v1, (Map<Object, Object>) v2); } else { V existingV = m1.get(k); if (existingV != null && existingV.equals(v2)) { } else { m1.put(k, v2); |
Map | deepMerge(Map deep Merge for (String key : newMap.keySet()) { if (newMap.get(key) instanceof Map && original.get(key) instanceof Map) { Map<String, Object> originalChild = (Map<String, Object>) original.get(key); Map<String, Object> newChild = (Map) newMap.get(key); original.put(key, deepMerge(originalChild, newChild)); } else { original.put(key, newMap.get(key)); return original; |
Map | merge(final Map Clones the lhs map and add all things from the rhs map. Map<K, V> result = null; if (lhs == null || lhs.size() == 0) { result = copy(rhs); } else if (rhs == null || rhs.size() == 0) { result = copy(lhs); } else { result = copy(lhs); result.putAll(rhs); ... |
Map | merge(final Map merge final HashMap<K, V> ret = new HashMap<K, V>(map1); ret.putAll(map2); return ret; |
HashMap | merge(final Map Merges specified maps into one new map and returns it. int size = 0; for (final Map<K, V> map : maps) { if (map != null) { size += map.size(); final HashMap<K, V> merged = new HashMap<K, V>(size); for (final Map<K, V> map : maps) { ... |
Map | merge(final Map Merge one context onto another by adding or replacing values. final HashMap<String, Map<String, String>> result = deepCopy(targetContext); for (final Map.Entry<String, Map<String, String>> entry : newContext.entrySet()) { if (!targetContext.containsKey(entry.getKey())) { result.put(entry.getKey(), new HashMap<String, String>()); } else { result.put(entry.getKey(), new HashMap<String, String>(targetContext.get(entry.getKey()))); result.get(entry.getKey()).putAll(entry.getValue()); ... |
Map | merge(List Merge/combine a list of Map if ((list == null) || (list.isEmpty())) { return null; Map<Character, Long> merged = new HashMap<>(); for (Map<Character, Long> map : list) { if ((map == null) || (map.isEmpty())) { continue; for (Map.Entry<Character, Long> entry : map.entrySet()) { char base = entry.getKey(); Long count = merged.get(base); if (count == null) { merged.put(base, entry.getValue()); } else { merged.put(base, (count + entry.getValue())); return merged; |
HashMap | merge(Map map1, Map map2) Creates a new HashMap that has all of the elements of map1 and map2 (on key collision, the latter override the former).
HashMap retval = new HashMap(calcCapacity(map1.size() + map2.size())); retval.putAll(map1); retval.putAll(map2); return retval; |
void | merge(Map options, Map addition) merge for (Object o : addition.entrySet()) { Map.Entry entry = (Map.Entry) o; if (entry.getValue() == null) options.remove(entry.getKey()); else options.put(entry.getKey(), entry.getValue()); |