JsonArray.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
package com.ishchuk.antlr.json.model;
import java.util.ArrayList;
import java.util.List;
public class JsonArray extends JsonElement {
private List<JsonElement> array;
public List<JsonElement> getArray() {
return array;
}
public JsonArray() {
this.array = new ArrayList<>();
}
public String toString() {
StringBuilder builder = new StringBuilder();
builder.append("[");
this.array.forEach(obj ->{
builder.append(obj.toString()).append(",");
});
int lastIndex = builder.lastIndexOf(",");
if (lastIndex > 0) {
builder.deleteCharAt(lastIndex);
}
builder.append("]");
return builder.toString();
}
@Override
public String toYml(String delay) {
StringBuilder builder = new StringBuilder();
this.array.forEach(obj ->{
builder.append(delay).append("- ");
if (obj instanceof JsonPrimitive) {
builder.append(obj.toString()).append("\n");
} else {
builder.append(obj.toYml(""));
}
});
return builder.toString();
}
public static void main() {
System.out.println("Hello! With this application you can parse a JSON file and convert it to YAML");
System.out.println("-----------------------------------------------------------------------------");
System.out.println("Put ");
}
}