Skip to content

Commit 258514d

Browse files
author
jan
committed
Add copy constructor and remove boolean parameter from toKeyValues
The boolean parameter toKeyValues didn't make sense anymore with all the changes to KeyValueTree (due to AutoBuild Serialisation)and the value was always false.
1 parent d38ebba commit 258514d

File tree

1 file changed

+30
-7
lines changed

1 file changed

+30
-7
lines changed

io.sloeber.autoBuild/src/io/sloeber/autoBuild/helpers/api/KeyValueTree.java

+30-7
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class KeyValueTree {
2424
private KeyValueTree myParent;
2525

2626
public static KeyValueTree createRoot() {
27-
return new KeyValueTree(null, null);
27+
return new KeyValueTree((String)null,(String) null);
2828
}
2929

3030
private KeyValueTree(String newKey, String newValue) {
@@ -34,6 +34,33 @@ private KeyValueTree(String newKey, String newValue) {
3434
myParent = null;
3535
}
3636

37+
/**
38+
* Copy constructor from this location (parent of source is ignored
39+
* Note this copy constructor assumes the strings themselves are not changed.
40+
*
41+
* @param source
42+
*/
43+
public KeyValueTree(KeyValueTree source) {
44+
this( source, null);
45+
}
46+
47+
private KeyValueTree(KeyValueTree source, KeyValueTree parent) {
48+
myChildren = new TreeMap<>();
49+
myKey = source.myKey;
50+
myValue = source.myValue;
51+
myParent = parent;
52+
copyChildren(source.myChildren);
53+
}
54+
55+
private void copyChildren(Map<String, KeyValueTree> children) {
56+
if(children==null) {
57+
return;
58+
}
59+
for(Entry<String, KeyValueTree> curChild:children.entrySet()) {
60+
myChildren.put(curChild.getKey(),new KeyValueTree(curChild.getValue(),this));
61+
}
62+
}
63+
3764
public KeyValueTree getParent() {
3865
return this.myParent;
3966
}
@@ -94,12 +121,8 @@ public Map<String, String> toKeyValues(boolean addParents) {
94121
return toKeyValues(EMPTY_STRING, theRoot);
95122
}
96123

97-
public Map<String, String> toKeyValues(String prefix, boolean addParents) {
98-
KeyValueTree theRoot = this;
99-
if (addParents) {
100-
theRoot = null;
101-
}
102-
return toKeyValues(prefix, theRoot);
124+
public Map<String, String> toKeyValues(String prefix) {
125+
return toKeyValues(prefix, this);
103126
}
104127

105128
public String dump() {

0 commit comments

Comments
 (0)