Blame view

src/main/java/com/ishchuk/antlr/json/model/JsonArray.java 1.43 KB
ea3b85f2   eishchuk   Initial commit
1
2
3
4
5
6
7
  package com.ishchuk.antlr.json.model;
  
  import java.util.ArrayList;
  import java.util.List;
  
  public class JsonArray extends JsonElement {
  
33a6a1e0   eishchuk   Converter to Yml
8
      private List<JsonElement> array;
ea3b85f2   eishchuk   Initial commit
9
  
33a6a1e0   eishchuk   Converter to Yml
10
      public List<JsonElement> getArray() {
ea3b85f2   eishchuk   Initial commit
11
12
13
          return array;
      }
  
ea3b85f2   eishchuk   Initial commit
14
15
16
      public JsonArray() {
          this.array = new ArrayList<>();
      }
33a6a1e0   eishchuk   Converter to Yml
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
  
      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 ");
      }
ea3b85f2   eishchuk   Initial commit
52
  }