Skip to content

Commit

Permalink
yaml copykey: deeper copy
Browse files Browse the repository at this point in the history
  • Loading branch information
mcmonkey4eva committed Jan 12, 2021
1 parent 0eff1c3 commit b853b25
Showing 1 changed file with 24 additions and 4 deletions.
Expand Up @@ -611,14 +611,34 @@ public void run() {
}
}

public Object deepCopyObject(Object obj) {
if (obj == null) {
return null;
}
if (obj instanceof YamlConfiguration) {
return copySection((YamlConfiguration) obj);
}
else if (obj instanceof List) {
ArrayList outList = new ArrayList(((List) obj).size());
for (Object subValue : (List) obj) {
outList.add(deepCopyObject(subValue));
}
return outList;
}
else if (obj instanceof Map) {
LinkedHashMap newMap = new LinkedHashMap();
for (Map.Entry<Object, Object> entry : ((Map<Object, Object>) obj).entrySet()) {
newMap.put(deepCopyObject(entry.getKey()), deepCopyObject(entry.getValue()));
}
}
return obj;
}

public YamlConfiguration copySection(YamlConfiguration section) {
YamlConfiguration newSection = new YamlConfiguration();
for (StringHolder key : section.getKeys(false)) {
Object obj = section.get(key.str);
if (obj instanceof YamlConfiguration) {
obj = copySection((YamlConfiguration) obj);
}
newSection.set(key.str, obj);
newSection.set(key.str, deepCopyObject(obj));
}
return newSection;
}
Expand Down

0 comments on commit b853b25

Please sign in to comment.