/** * Merges the given map with this ConfigObject overriding any matching configuration entries in this ConfigObject * * @param other The ConfigObject to merge with * @return The result of the merge */ public Map merge(ConfigObject other) { return doMerge(this, other); }
private Map doMerge(Map config, Map other) { for (Object o : other.entrySet()) { Map.Entry next = (Map.Entry) o; Object key = next.getKey(); Object value = next.getValue(); Object configEntry = config.get(key); if (configEntry == null) { config.put(key, value); } else { if (configEntry instanceof Map && !((Map) configEntry).isEmpty() && value instanceof Map) { // recur doMerge((Map) configEntry, (Map) value); } else { config.put(key, value); } } } return config; }
/** * Merges the given map with this ConfigObject overriding any matching configuration entries in this ConfigObject * * @param other The ConfigObject to merge with * @return The result of the merge */ public Map merge(ConfigObject other) { return doMerge(this, other); }
private Map doMerge(Map config, Map other) { for (Object o : other.entrySet()) { Map.Entry next = (Map.Entry) o; String key = (String) next.getKey(); Object value = next.getValue(); Object configEntry = config.get(key); if (configEntry == null) { config.put(key, value); continue; } else { if (configEntry instanceof Map && ((Map)configEntry).size() > 0 && value instanceof Map) { // recur doMerge((Map) configEntry, (Map) value); } else { config.put(key, value); } } } return config; }