Transférer les fichiers vers 'src/JsonInspector'
This commit is contained in:
parent
f5a1da67c5
commit
9828f30743
@ -31,21 +31,21 @@ public class GraphicFile extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void createFileRecursive(Node node, int depth, boolean inList) {
|
private void createFileRecursive(Node node, int depth, boolean virgule) {
|
||||||
String indentation = "";
|
String indentation = "";
|
||||||
|
|
||||||
for (int i = 0; i < depth; i++) {
|
for (int i = 0; i < depth; i++) {
|
||||||
indentation += Parameters.IHM_INDENTATION;
|
indentation += Parameters.IHM_INDENTATION;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (node.getType() == Type.OBJECT) {
|
if (node.getType() == Type.OBJECT || node.getType() == Type.ELEMENT) {
|
||||||
createObject(node, depth, indentation);
|
createObjectElement(node, depth, indentation, virgule);
|
||||||
|
|
||||||
} else if (node.getType() == Type.ARRAY) {
|
} else if (node.getType() == Type.ARRAY) {
|
||||||
createArray(node, depth, indentation);
|
createArray(node, depth, indentation, virgule);
|
||||||
|
|
||||||
} else if (node.getType() == Type.PAIR) {
|
} else if (node.getType() == Type.PAIR) {
|
||||||
createPair(node, depth, indentation, inList);
|
createPair(node, depth, indentation, virgule);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -57,7 +57,7 @@ public class GraphicFile extends JPanel {
|
|||||||
line.add(": ");
|
line.add(": ");
|
||||||
|
|
||||||
if (node.getSize() != 0) {
|
if (node.getSize() != 0) {
|
||||||
line.add("\"" + node.get(0) + "\"", Parameters.STRING_COLOR);
|
createValue(line, node.get(0));
|
||||||
} else {
|
} else {
|
||||||
line.add("null" , Parameters.OTHER_COLOR);
|
line.add("null" , Parameters.OTHER_COLOR);
|
||||||
}
|
}
|
||||||
@ -70,52 +70,93 @@ public class GraphicFile extends JPanel {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void createObject(Node node, int depth, String indentation) {
|
private void createObjectElement(Node node, int depth, String indentation, boolean virgule) {
|
||||||
Line line = new Line(node, depth);
|
Line line = new Line(node, depth);
|
||||||
line.add(indentation);
|
line.add(indentation);
|
||||||
|
|
||||||
if (node.getName().equals("")) {
|
if (node.getType() == Type.ELEMENT) {
|
||||||
line.add("{");
|
line.add("{");
|
||||||
} else {
|
} else {
|
||||||
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
||||||
line.add(": {");
|
line.add(": {");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.getSize() == 0) {
|
||||||
|
if (virgule) {
|
||||||
|
line.add(" },");
|
||||||
|
} else {
|
||||||
|
line.add(" }");
|
||||||
|
}
|
||||||
|
lines.add(line);
|
||||||
|
|
||||||
|
} else {
|
||||||
lines.add(line);
|
lines.add(line);
|
||||||
callNextNodes(node, depth);
|
callNextNodes(node, depth);
|
||||||
lines.add(new Line(node, indentation + "}", depth));
|
Line endLine = new Line(node, indentation + "}", depth);
|
||||||
|
|
||||||
|
if (virgule) {
|
||||||
|
endLine.add(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
lines.add(endLine);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private void createArray(Node node, int depth, String indentation) {
|
private void createArray(Node node, int depth, String indentation, boolean virgule) {
|
||||||
Line line = new Line(node, depth);
|
Line line = new Line(node, depth);
|
||||||
line.add(indentation);
|
line.add(indentation);
|
||||||
|
|
||||||
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
line.add("\"" + node.getName() + "\"", Parameters.KEY_COLOR);
|
||||||
line.add(": [");
|
line.add(": [");
|
||||||
|
|
||||||
|
if (node.getSize() == 0) {
|
||||||
|
if (virgule) {
|
||||||
|
line.add(" ],");
|
||||||
|
} else {
|
||||||
|
line.add(" ]");
|
||||||
|
}
|
||||||
|
lines.add(line);
|
||||||
|
} else {
|
||||||
lines.add(line);
|
lines.add(line);
|
||||||
|
|
||||||
for (int i = 0; i < node.getSize(); i++) {
|
for (int i = 0; i < node.getSize(); i++) {
|
||||||
Line valueLine = new Line(node, depth + 1);
|
Line valueLine = new Line(node, depth + 1);
|
||||||
|
|
||||||
if (node.get(i).isObjectOrArray()) {
|
if (node.get(i).isNode()) {
|
||||||
callNextNodes(node, depth);
|
callNextNodes(node, depth);
|
||||||
} else {
|
} else {
|
||||||
valueLine.add(
|
String valueString = indentation + Parameters.IHM_INDENTATION;
|
||||||
indentation + Parameters.IHM_INDENTATION + "\"" + node.get(i).getValue() + "\"",
|
valueLine.add(valueString, Parameters.STRING_COLOR);
|
||||||
Parameters.STRING_COLOR
|
createValue(valueLine, node.get(i));
|
||||||
);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (i != node.getSize() - 1) {
|
if (i != node.getSize() - 1) {
|
||||||
valueLine.add(",");
|
valueLine.add(",");
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
lines.add(valueLine);
|
lines.add(valueLine);
|
||||||
}
|
}
|
||||||
|
|
||||||
lines.add(new Line(node, indentation + "]", depth));
|
Line endLine = new Line(node, indentation + "]", depth);
|
||||||
|
|
||||||
|
if (virgule) {
|
||||||
|
endLine.add(",");
|
||||||
|
}
|
||||||
|
|
||||||
|
lines.add(endLine);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
private void createValue(Line line, Value value) {
|
||||||
|
if (value.isNumber()) {
|
||||||
|
line.add("" + value.getValue(), Parameters.NUMBER_COLOR);
|
||||||
|
} else if (value.isString()) {
|
||||||
|
line.add("\"" + value.getValue() + "\"", Parameters.STRING_COLOR);
|
||||||
|
} else {
|
||||||
|
line.add("" + value.getValue(), Parameters.OTHER_COLOR);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -191,13 +232,17 @@ public class GraphicFile extends JPanel {
|
|||||||
|
|
||||||
|
|
||||||
private Node createTree() {
|
private Node createTree() {
|
||||||
Node beginning = new Node("", Type.OBJECT);
|
Node beginning = new Node("", Type.ELEMENT);
|
||||||
Node d = new Node("d", Type.OBJECT);
|
Node d = new Node("d", Type.OBJECT);
|
||||||
Node result = new Node("result", Type.ARRAY);
|
Node result = new Node("result", Type.ARRAY);
|
||||||
Node metadata = new Node("", Type.ELEMENT);
|
Node metadata = new Node("", Type.ELEMENT);
|
||||||
Node type = new Node("type", Type.PAIR);
|
Node type = new Node("type", Type.PAIR);
|
||||||
Node e = new Node("e", Type.ARRAY);
|
Node e = new Node("e", Type.ARRAY);
|
||||||
String value1 = "EmployeeDetails.Employe", value2 = "E12012", value3 = "35";
|
Node key = new Node("key", Type.PAIR);
|
||||||
|
Node key2 = new Node("key2", Type.PAIR);
|
||||||
|
Node object = new Node("object", Type.OBJECT);
|
||||||
|
Integer number = 12;
|
||||||
|
String value1 = "EmployeeDetails.Employe", value2 = "E12012", value3 = "35", value4 = "string";
|
||||||
|
|
||||||
beginning.add(d);
|
beginning.add(d);
|
||||||
beginning.add(e);
|
beginning.add(e);
|
||||||
@ -207,6 +252,11 @@ public class GraphicFile extends JPanel {
|
|||||||
result.add(value1);
|
result.add(value1);
|
||||||
result.add(value2);
|
result.add(value2);
|
||||||
result.add(value3);
|
result.add(value3);
|
||||||
|
key.add(number);
|
||||||
|
beginning.add(key);
|
||||||
|
beginning.add(key2);
|
||||||
|
beginning.add(object);
|
||||||
|
key2.add(value4);
|
||||||
|
|
||||||
System.out.println(Tree.printTree(beginning, 0));
|
System.out.println(Tree.printTree(beginning, 0));
|
||||||
|
|
||||||
|
@ -3,7 +3,7 @@ package JsonInspector;
|
|||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
|
|
||||||
public class Tree {
|
public class Tree {
|
||||||
private Node firstNode;
|
private final Node firstNode;
|
||||||
|
|
||||||
|
|
||||||
public Tree(String file) {
|
public Tree(String file) {
|
||||||
@ -88,11 +88,11 @@ public class Tree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
if (node.getType() == Type.OBJECT){
|
if (node.getType() == Type.OBJECT || node.getType() == Type.ELEMENT) {
|
||||||
line += printObject(node, depth, indentation);
|
line += printObjectElement(node, depth, indentation);
|
||||||
|
|
||||||
} else if (node.getType() == Type.PAIR){
|
} else if (node.getType() == Type.PAIR){
|
||||||
line += printPair(node, depth, indentation);
|
line += printPair(node);
|
||||||
|
|
||||||
} else if (node.getType() == Type.ARRAY){
|
} else if (node.getType() == Type.ARRAY){
|
||||||
line += printArray(node, depth, indentation);
|
line += printArray(node, depth, indentation);
|
||||||
@ -109,17 +109,26 @@ public class Tree {
|
|||||||
if (node.get(i).isNode()) {
|
if (node.get(i).isNode()) {
|
||||||
line += "\n" + printTree((Node) node.get(i).getValue(), depth + 1);
|
line += "\n" + printTree((Node) node.get(i).getValue(), depth + 1);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (i != node.getSize() - 1) {
|
||||||
|
line += ",";
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static String printPair(Node node, int depth, String indentation) {
|
private static String printPair(Node node) {
|
||||||
String line = "";
|
String line = "";
|
||||||
|
|
||||||
if (node.getSize() != 0) {
|
if (node.getSize() != 0) {
|
||||||
line += ": " + node.get(0);
|
if (node.get(0).isString()) {
|
||||||
|
line += ": \"" + node.get(0).getValue() + "\"";
|
||||||
|
} else {
|
||||||
|
line += ": " + node.get(0).getValue();
|
||||||
|
}
|
||||||
|
|
||||||
} else {
|
} else {
|
||||||
line += ": null";
|
line += ": null";
|
||||||
}
|
}
|
||||||
@ -128,17 +137,21 @@ public class Tree {
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
private static String printObject(Node node, int depth, String indentation) {
|
private static String printObjectElement(Node node, int depth, String indentation) {
|
||||||
String line = "";
|
String line = "";
|
||||||
|
|
||||||
if (node.getName().equals("")) {
|
if (node.getType() == Type.ELEMENT) {
|
||||||
line += "{";
|
line += "{";
|
||||||
} else {
|
} else {
|
||||||
line += ": {";
|
line += ": {";
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if (node.getSize() == 0) {
|
||||||
|
line += "}";
|
||||||
|
} else {
|
||||||
line += callNextNodes(node, depth);
|
line += callNextNodes(node, depth);
|
||||||
line += "\n" + indentation + "}";
|
line += "\n" + indentation + "}";
|
||||||
|
}
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
@ -146,20 +159,31 @@ public class Tree {
|
|||||||
|
|
||||||
private static String printArray(Node node, int depth, String indentation) {
|
private static String printArray(Node node, int depth, String indentation) {
|
||||||
String line = "";
|
String line = "";
|
||||||
|
line += ": [";
|
||||||
|
|
||||||
line += ": [\n";
|
if (node.getSize() == 0) {
|
||||||
|
line += "]";
|
||||||
|
|
||||||
for (int i = 0; i < node.getSize(); i++) {
|
|
||||||
//si la valeur a l'indice i est la dernière alors pas de virgule
|
|
||||||
if (i != node.getSize()-1) {
|
|
||||||
line += indentation + Parameters.CONSOLE_INDENTATION + node.get(i).getValue() + ",\n";
|
|
||||||
} else {
|
} else {
|
||||||
line += indentation + Parameters.CONSOLE_INDENTATION + node.get(i).getValue();
|
for (int i = 0; i < node.getSize(); i++) {
|
||||||
|
if (node.get(i).isNode()) {
|
||||||
|
line += "\n" + printTree((Node) node.get(i).getValue(), depth + 1);
|
||||||
|
} else {
|
||||||
|
line += indentation + Parameters.CONSOLE_INDENTATION;
|
||||||
|
if (node.get(i).isString()) {
|
||||||
|
line += "\"" + node.get(i).getValue() + "\"";
|
||||||
|
} else {
|
||||||
|
line += node.get(i).getValue();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
if (i != node.getSize() - 1) {
|
||||||
|
line += ",\n";
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
line += callNextNodes(node, depth);
|
|
||||||
line += "\n" + indentation + "]";
|
line += "\n" + indentation + "]";
|
||||||
|
}
|
||||||
|
|
||||||
return line;
|
return line;
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user