|
1 | 1 | package kdl.objects;
|
2 | 2 |
|
3 |
| -import kdl.print.PrintConfig; |
4 |
| -import kdl.print.PrintUtil; |
5 |
| - |
6 | 3 | import java.io.IOException;
|
7 | 4 | import java.io.Writer;
|
8 | 5 | import java.math.BigDecimal;
|
9 |
| -import java.util.*; |
| 6 | +import java.util.ArrayList; |
| 7 | +import java.util.Collections; |
| 8 | +import java.util.HashMap; |
| 9 | +import java.util.List; |
| 10 | +import java.util.Map; |
| 11 | +import java.util.Objects; |
| 12 | +import java.util.Optional; |
10 | 13 | import java.util.concurrent.ConcurrentHashMap;
|
11 | 14 | import java.util.function.Predicate;
|
| 15 | +import kdl.print.PrintConfig; |
| 16 | + |
| 17 | +import static kdl.print.PrintUtil.writeStringQuotedAppropriately; |
12 | 18 |
|
13 | 19 | public class KDLNode implements KDLObject {
|
14 | 20 | private final String identifier;
|
@@ -69,41 +75,31 @@ public void writeKDL(Writer writer, PrintConfig printConfig) throws IOException
|
69 | 75 | void writeKDLPretty(Writer writer, int depth, PrintConfig printConfig) throws IOException {
|
70 | 76 | if (type.isPresent()) {
|
71 | 77 | writer.write('(');
|
72 |
| - PrintUtil.writeStringQuotedAppropriately(writer, type.get(), true, printConfig); |
| 78 | + writeStringQuotedAppropriately(writer, type.get(), true, printConfig); |
73 | 79 | writer.write(')');
|
74 | 80 | }
|
75 | 81 |
|
76 |
| - PrintUtil.writeStringQuotedAppropriately(writer, identifier, true, printConfig); |
77 |
| - if (!args.isEmpty() || !props.isEmpty() || child.isPresent()) { |
78 |
| - writer.write(' '); |
79 |
| - } |
| 82 | + writeStringQuotedAppropriately(writer, identifier, true, printConfig); |
80 | 83 |
|
81 |
| - for (int i = 0; i < this.args.size(); i++) { |
82 |
| - final KDLValue<?> value = this.args.get(i); |
83 |
| - if (!(value instanceof KDLNull) || printConfig.shouldPrintNullArgs()) { |
84 |
| - value.writeKDL(writer, printConfig); |
85 |
| - if (i < this.args.size() - 1 || !props.isEmpty() || child.isPresent()) { |
86 |
| - writer.write(' '); |
87 |
| - } |
88 |
| - } |
89 |
| - } |
| 84 | + for (var value : this.args) { |
| 85 | + if (!(value instanceof KDLNull) || printConfig.shouldPrintNullArgs()) { |
| 86 | + writer.write(' '); |
| 87 | + value.writeKDL(writer, printConfig); |
| 88 | + } |
| 89 | + } |
90 | 90 |
|
91 |
| - final ArrayList<String> keys = new ArrayList<>(props.keySet()); |
92 |
| - for (int i = 0; i < keys.size(); i++) { |
93 |
| - final KDLValue<?> value = props.get(keys.get(i)); |
94 |
| - if (!(value instanceof KDLNull) || printConfig.shouldPrintNullProps()) { |
95 |
| - PrintUtil.writeStringQuotedAppropriately(writer, keys.get(i), true, printConfig); |
96 |
| - writer.write('='); |
97 |
| - value.writeKDL(writer, printConfig); |
98 |
| - if (i < keys.size() - 1 || child.isPresent()) { |
99 |
| - writer.write(' '); |
100 |
| - } |
101 |
| - } |
102 |
| - } |
| 91 | + for (var entry : props.entrySet()) { |
| 92 | + if (!(entry.getValue() instanceof KDLNull) || printConfig.shouldPrintNullProps()) { |
| 93 | + writer.write(' '); |
| 94 | + writeStringQuotedAppropriately(writer, entry.getKey(), true, printConfig); |
| 95 | + writer.write('='); |
| 96 | + entry.getValue().writeKDL(writer, printConfig); |
| 97 | + } |
| 98 | + } |
103 | 99 |
|
104 | 100 | if (child.isPresent()) {
|
105 | 101 | if (!child.get().getNodes().isEmpty() || printConfig.shouldPrintEmptyChildren()) {
|
106 |
| - writer.write('{'); |
| 102 | + writer.write(" {"); |
107 | 103 | writer.write(printConfig.getNewline());
|
108 | 104 | child.get().writeKDL(writer, depth + 1, printConfig);
|
109 | 105 | for (int i = 0; i < printConfig.getIndent() * depth; i++) {
|
|
0 commit comments