Transférer les fichiers vers 'src/JsonInspector'

This commit is contained in:
Romain BESSON 2023-01-15 18:26:16 +01:00
parent 9fe24c2f98
commit 630f3565c1
2 changed files with 24 additions and 27 deletions

View File

@ -6,13 +6,8 @@ public class Tree {
private Node firstNode; private Node firstNode;
public Tree(String file) { public Tree(String file) throws JsonSyntaxException {
try {
firstNode = parseElement(file); firstNode = parseElement(file);
} catch (JsonSyntaxException e) {
e.printStackTrace();
//System.err.println("Syntax error while parsing JSON file");
}
} }
@ -22,13 +17,19 @@ public class Tree {
if (keyValue.length == 2) { if (keyValue.length == 2) {
String key = keyValue[0], value = keyValue[1]; String key = keyValue[0], value = keyValue[1];
if (0 < value.length()) {
if (value.charAt(0) == '[' && value.charAt(value.length() - 1) == ']') { if (value.charAt(0) == '[' && value.charAt(value.length() - 1) == ']') {
return parseArray(key, value); return parseArray(key, value);
} else if (value.charAt(0) == '{' && value.charAt(value.length() - 1) == '}') { } else if (value.charAt(0) == '{' && value.charAt(value.length() - 1) == '}') {
return parseObject(key, value); return parseObject(key, value);
} else { } else {
return parsePair(key, value); return parsePair(key, value);
} }
} else {
return null;
}
} else if (keyValue[0].equals("")) { } else if (keyValue[0].equals("")) {
@ -45,11 +46,11 @@ public class Tree {
private Node parseArray(String name, String rawValues) throws JsonSyntaxException { private Node parseArray(String name, String rawValues) throws JsonSyntaxException {
Node array = new Node(name, Type.ARRAY); Node array = new Node(cleanOpeningExpression(name), Type.ARRAY);
ArrayList<String> elements = splitList(rawValues); ArrayList<String> elements = splitList(rawValues);
for (String value : elements) { for (String value : elements) {
if (0 < value.length()) {
if (value.charAt(0) == '{') { if (value.charAt(0) == '{') {
if (value.charAt(value.length() - 1) == '}') { if (value.charAt(value.length() - 1) == '}') {
array.add(parseElement(value)); array.add(parseElement(value));
@ -61,13 +62,14 @@ public class Tree {
array.add(value); array.add(value);
} }
} }
}
return array; return array;
} }
private Node parseObject(String name, String rawValues) throws JsonSyntaxException { private Node parseObject(String name, String rawValues) throws JsonSyntaxException {
Node object = new Node(name, Type.OBJECT); Node object = new Node(cleanOpeningExpression(name), Type.OBJECT);
ArrayList<String> elements = splitList(rawValues); ArrayList<String> elements = splitList(rawValues);
for (String value : elements) { for (String value : elements) {
@ -98,7 +100,7 @@ public class Tree {
} }
private String cleanOpeningExpression(String strToClean) { public static String cleanOpeningExpression(String strToClean) {
StringBuilder cleanedString = new StringBuilder(strToClean); StringBuilder cleanedString = new StringBuilder(strToClean);
cleanedString.deleteCharAt(0); cleanedString.deleteCharAt(0);
cleanedString.deleteCharAt(cleanedString.length()-1); cleanedString.deleteCharAt(cleanedString.length()-1);

View File

@ -41,9 +41,4 @@ public class Value <T> {
public boolean isNumber() { public boolean isNumber() {
return value.getClass().equals(Integer.class) || value.getClass().equals(Double.class); return value.getClass().equals(Integer.class) || value.getClass().equals(Double.class);
} }
public boolean isBoolean() {
return value.getClass().equals(Boolean.class);
}
} }