JsonObject.java
1.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package com.ishchuk.antlr.json.model;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;
public class JsonObject extends JsonElement {
private Map<String, JsonElement> map;
public Map<String, JsonElement> getMap() {
return map;
}
public void setMap(Map<String, JsonElement> map) {
this.map = map;
}
public JsonObject() {
this.map = new HashMap<>();
}
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("{");
this.map.keySet().forEach(key -> {
builder.append(key)
.append(":")
.append(map.get(key).toString())
.append(",");
});
int lastInd = builder.lastIndexOf(",");
if (lastInd > 0) {
builder.deleteCharAt(lastInd);
}
builder.append("}");
return builder.toString();
}
@Override
public String toYml(String delay) {
StringBuilder builder = new StringBuilder();
this.map.keySet().forEach(key -> {
builder.append(delay).append(key).append(": ");
if (this.map.get(key) instanceof JsonPrimitive) {
builder.append(this.map.get(key).toString()).append("\n");
} else {
builder.append("\n").append(this.map.get(key).toYml(delay + " "));
}
});
return builder.toString();
}
}