Skip to content
This repository has been archived by the owner on Aug 30, 2023. It is now read-only.

Commit

Permalink
feat(configs): add extra checks to depth config mapping
Browse files Browse the repository at this point in the history
refs: #181
  • Loading branch information
ChrisRousey committed Mar 23, 2023
1 parent 21a5f09 commit 1497329
Showing 1 changed file with 16 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -70,15 +70,16 @@ public static Map<String, Object> toObjectMap(JsonNode json) {
* the `.putAll()` method would overwrite some keys. To avoid this, this method was implemented.
* It takes a map, `prio2`, and overwrites the values/adds the keys from another map, `prio1`
*
* @param prio2 map with the lowest priority
* @param prio1 map with the highest priority. Values from this map overwrite values from prio2
* @param lower_priority_map map with the lowest priority
* @param higher_priority_map map with the highest priority. Values from this map overwrite values
* from prio2
* @return a combined map
*/
public static Map<String, Object> combineMaps(
Map<String, Object> prio2, Map<String, Object> prio1) {
Map<String, Object> result = new HashMap<>(prio2);
Map<String, Object> lower_priority_map, Map<String, Object> higher_priority_map) {
Map<String, Object> result = new HashMap<>(lower_priority_map);
// loop over prio1 map to replace values
for (Map.Entry<String, Object> entry : prio1.entrySet()) {
for (Map.Entry<String, Object> entry : higher_priority_map.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (result.containsKey(key)) {
Expand All @@ -89,12 +90,18 @@ public static Map<String, Object> combineMaps(
result.put(
key, combineMaps((Map<String, Object>) value, (Map<String, Object>) existingValue));
} else {
// if it is now a map, overwrite the value
result.put(key, value);
// do not overwrite value if it is empty
if (value != "") {
// if it is now a map, overwrite the value
result.put(key, value);
}
}
} else {
// add the value if it doesn't exist
result.put(key, value);
// do not add value if it is empty
if (value != "") {
// add the value if it doesn't exist
result.put(key, value);
}
}
}
return result;
Expand Down

0 comments on commit 1497329

Please sign in to comment.