diff --git a/src/.idea/workspace.xml b/src/.idea/workspace.xml
new file mode 100644
index 0000000..e25f683
--- /dev/null
+++ b/src/.idea/workspace.xml
@@ -0,0 +1,90 @@
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+ 1673809886930
+
+
+ 1673809886930
+
+
+
+
+
+
+
+
+
+
+
\ No newline at end of file
diff --git a/src/CoreJSONDescriptor.java b/src/CoreJSONDescriptor.java
deleted file mode 100644
index 6c523cd..0000000
--- a/src/CoreJSONDescriptor.java
+++ /dev/null
@@ -1,47 +0,0 @@
-package JsonInspector;
-
-import java.io.File;
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.FileReader;
-import java.net.URL;
-
-public class CoreJSONDescriptor {
- public static void main(String[] args) {
-
- if (args.length == 0) {
- new Frame();
- } else {
- File jsonFile = new File("toFormat.json");
-
- if(jsonFile.exists()) {
- //new Descriptor(getCodeJsonInOneLine(jsonFile));
- } else {
- System.err.println("[!] Probleme lors de l'ouverture du fichier");
- System.exit(-1);
- }
- }
- }
-
- public static String getCodeJsonInOneLine(File f) {
- StringBuilder sb = new StringBuilder();
-
- try {
- BufferedReader buff = new BufferedReader(new FileReader(f));
- String line;
- while ((line = buff.readLine()) != null) {
- line = line.replaceAll("\t", "");
- line = line.replaceAll("\n", "");
- line = line.replaceAll(" ", "");
- sb.append(line);
- }
-
- buff.close();
- } catch (IOException e) {
- System.err.println("[!] Probleme lors de l'ouverture du fichier");
- System.exit(-1);
- }
-
- return sb.toString();
- }
-}
diff --git a/src/JsonSyntaxException.java b/src/fr/sae/JSonInspector/Exception/JsonSyntaxException.java
similarity index 82%
rename from src/JsonSyntaxException.java
rename to src/fr/sae/JSonInspector/Exception/JsonSyntaxException.java
index 3fd2f7e..12c5190 100644
--- a/src/JsonSyntaxException.java
+++ b/src/fr/sae/JSonInspector/Exception/JsonSyntaxException.java
@@ -1,4 +1,4 @@
-package JsonInspector;
+package fr.sae.JSonInspector.Exception;
public class JsonSyntaxException extends Throwable {
private static final String MESSAGE = "Syntax error in JSON file";
diff --git a/src/ArrayObjectListener.java b/src/fr/sae/JSonInspector/Graphics/ArrayObjectListener.java
similarity index 70%
rename from src/ArrayObjectListener.java
rename to src/fr/sae/JSonInspector/Graphics/ArrayObjectListener.java
index 58b0db8..e4061ef 100644
--- a/src/ArrayObjectListener.java
+++ b/src/fr/sae/JSonInspector/Graphics/ArrayObjectListener.java
@@ -1,4 +1,4 @@
-package JsonInspector;
+package fr.sae.JSonInspector.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
@@ -7,7 +7,6 @@ public class ArrayObjectListener implements MouseListener {
private final Line line;
private final Frame frame;
-
public ArrayObjectListener(Line line, Frame frame) {
this.line = line;
this.frame = frame;
@@ -24,14 +23,18 @@ public class ArrayObjectListener implements MouseListener {
}
@Override
- public void mousePressed(MouseEvent e) {}
+ public void mousePressed(MouseEvent e) {
+ }
@Override
- public void mouseReleased(MouseEvent e) {}
+ public void mouseReleased(MouseEvent e) {
+ }
@Override
- public void mouseEntered(MouseEvent e) {}
+ public void mouseEntered(MouseEvent e) {
+ }
@Override
- public void mouseExited(MouseEvent e) {}
+ public void mouseExited(MouseEvent e) {
+ }
}
diff --git a/src/Frame.java b/src/fr/sae/JSonInspector/Graphics/Frame.java
similarity index 92%
rename from src/Frame.java
rename to src/fr/sae/JSonInspector/Graphics/Frame.java
index 978e180..0513cc0 100644
--- a/src/Frame.java
+++ b/src/fr/sae/JSonInspector/Graphics/Frame.java
@@ -1,4 +1,9 @@
-package JsonInspector;
+package fr.sae.JSonInspector.Graphics;
+
+import fr.sae.JSonInspector.Exception.JsonSyntaxException;
+import fr.sae.JSonInspector.Main;
+import fr.sae.JSonInspector.Settings.Parameters;
+import fr.sae.JSonInspector.Storage.Tree;
import javax.swing.*;
import java.awt.*;
@@ -15,25 +20,22 @@ public class Frame extends JFrame {
private GraphicFile file;
private Tree tree;
-
public Frame() {
super("Inspecteur JSON");
init();
this.setVisible(true);
}
-
private void init() {
this.setSize(DEFAULT_FRAME_SIZE);
this.setDefaultCloseOperation(EXIT_ON_CLOSE);
this.setMinimumSize(MINIMUM_FRAME_SIZE);
this.setLayout(cards);
this.add(firstCard());
- //this.add(secondCard());
+ // this.add(secondCard());
cards.first(this.getContentPane());
}
-
private JPanel firstCard() {
GridBagLayout layout = new GridBagLayout();
GridBagConstraints gbc = new GridBagConstraints();
@@ -44,8 +46,8 @@ public class Frame extends JFrame {
panel.setLayout(layout);
gbc.insets = new Insets(10, 10, 10, 10);
- gbc.gridx = 0;
- gbc.gridy = 0;
+ gbc.gridx = 0;
+ gbc.gridy = 0;
JLabel label = new JLabel("URL :");
label.setForeground(Parameters.DEFAULT_TEXT_COLOR);
panel.add(label, gbc);
@@ -53,8 +55,8 @@ public class Frame extends JFrame {
gbc.gridx = 1;
panel.add(textField, gbc);
- gbc.gridx = 0;
- gbc.gridy = 1;
+ gbc.gridx = 0;
+ gbc.gridy = 1;
gbc.gridwidth = 2;
panel.add(button, gbc);
@@ -62,19 +64,16 @@ public class Frame extends JFrame {
return panel;
}
-
private JPanel secondCard() {
file = new GraphicFile(this, tree);
return initSecondCard(file);
}
-
private JPanel secondCard(GraphicFile file) {
this.file = file;
return initSecondCard(file);
}
-
private JPanel initSecondCard(GraphicFile file) {
JButton unfoldButton = new JButton("Tout déplier");
JButton retreatButton = new JButton("Tout replier");
@@ -100,19 +99,16 @@ public class Frame extends JFrame {
return mainPanel;
}
-
private void unfoldAction() {
file.showAll();
repaintFile();
}
-
private void retreatAction() {
file.retreatAll();
repaintFile();
}
-
public void repaintFile() {
file = new GraphicFile(this, file.getLines());
this.remove(secondCard);
@@ -121,7 +117,6 @@ public class Frame extends JFrame {
cards.last(this.getContentPane());
}
-
private void validationAction(JTextField field) {
try {
URL url = new URL(field.getText());
@@ -147,7 +142,6 @@ public class Frame extends JFrame {
}
}
-
private void backAction(JPanel panel) {
this.remove(panel);
cards.first(this.getContentPane());
diff --git a/src/GraphicFile.java b/src/fr/sae/JSonInspector/Graphics/GraphicFile.java
similarity index 93%
rename from src/GraphicFile.java
rename to src/fr/sae/JSonInspector/Graphics/GraphicFile.java
index 2fd87a1..76de8db 100644
--- a/src/GraphicFile.java
+++ b/src/fr/sae/JSonInspector/Graphics/GraphicFile.java
@@ -1,4 +1,10 @@
-package JsonInspector;
+package fr.sae.JSonInspector.Graphics;
+
+import fr.sae.JSonInspector.Settings.Parameters;
+import fr.sae.JSonInspector.Storage.Node;
+import fr.sae.JSonInspector.Storage.Tree;
+import fr.sae.JSonInspector.Storage.Type;
+import fr.sae.JSonInspector.Storage.Value;
import javax.swing.*;
import java.awt.*;
@@ -11,7 +17,6 @@ public class GraphicFile extends JPanel {
private ArrayList lines;
private Node firstNode;
-
public GraphicFile(Frame frame, Tree tree) {
super();
firstNode = tree.getFirstNode();
@@ -19,21 +24,19 @@ public class GraphicFile extends JPanel {
lines = new ArrayList<>();
this.frame = frame;
createFileRecursive(firstNode, 0, false);
- //displayAllLines();
+ // displayAllLines();
displayLines();
}
-
public GraphicFile(Frame frame, ArrayList lines) {
super();
init();
this.frame = frame;
this.lines = lines;
- //displayAllLines();
+ // displayAllLines();
displayLines();
}
-
private void init() {
this.setBackground(Parameters.BACKGROUND_COLOR);
this.setLayout(new FlowLayout(FlowLayout.LEFT));
@@ -43,7 +46,6 @@ public class GraphicFile extends JPanel {
this.add(alignementPanel);
}
-
private void createFileRecursive(Node node, int depth, boolean virgule) {
String indentation = "";
@@ -62,7 +64,6 @@ public class GraphicFile extends JPanel {
}
}
-
private void createPair(Node node, int depth, String indentation, boolean virgule) {
Line line = new Line(node, depth);
line.add(indentation);
@@ -72,7 +73,7 @@ public class GraphicFile extends JPanel {
if (node.getSize() != 0) {
createValue(line, node.get(0));
} else {
- line.add("null" , Parameters.OTHER_COLOR);
+ line.add("null", Parameters.OTHER_COLOR);
}
if (virgule) {
@@ -82,7 +83,6 @@ public class GraphicFile extends JPanel {
lines.add(line);
}
-
private void createObjectElement(Node node, int depth, String indentation, boolean virgule) {
Line line = new Line(node, depth);
line.add(indentation);
@@ -121,7 +121,6 @@ public class GraphicFile extends JPanel {
}
}
-
private void createArray(Node node, int depth, String indentation, boolean virgule) {
Line line = new Line(node, depth);
line.add(indentation);
@@ -173,7 +172,6 @@ public class GraphicFile extends JPanel {
}
}
-
private void createValue(Line line, Value value) {
if (value.isNumber()) {
line.add("" + value.getValue(), Parameters.NUMBER_COLOR);
@@ -184,7 +182,6 @@ public class GraphicFile extends JPanel {
}
}
-
private void callNextNodes(Node node, int depth) {
boolean virgule;
@@ -199,7 +196,6 @@ public class GraphicFile extends JPanel {
}
}
-
private void displayLines() {
boolean inArrayObject = false, array, object;
Node openedArrayObject = lines.get(0).getNode();
@@ -210,7 +206,8 @@ public class GraphicFile extends JPanel {
array = lines.get(i).getNode().isArray();
object = lines.get(i).getNode().isObject();
- // Vérifie si le noeud est du type ARRAY ou du type OBJECT et s'il doit être affiché
+ // Vérifie si le noeud est du type ARRAY ou du type OBJECT et s'il doit être
+ // affiché
if ((array || object) && !lines.get(i).isShow()) {
inArrayObject = true;
openedArrayObject = lines.get(i).getNode();
@@ -221,7 +218,7 @@ public class GraphicFile extends JPanel {
displayOneHidedLine(i, Parameters.OBJECT_ELEMENT_CLOSING);
}
- //Sinon affiche la ligne normalement
+ // Sinon affiche la ligne normalement
} else {
displayOneLine(i);
}
@@ -232,7 +229,6 @@ public class GraphicFile extends JPanel {
}
}
-
private void displayOneLine(int index) {
gbc.gridy = index;
@@ -240,7 +236,6 @@ public class GraphicFile extends JPanel {
alignementPanel.add(lines.get(index), gbc);
}
-
private void displayOneHidedLine(int index, String endOfLine) {
gbc.gridy = index;
@@ -249,7 +244,6 @@ public class GraphicFile extends JPanel {
alignementPanel.add(lines.get(index), gbc);
}
-
public void showAll() {
for (Line line : lines) {
if (!line.isShow()) {
@@ -259,7 +253,6 @@ public class GraphicFile extends JPanel {
}
}
-
public void retreatAll() {
for (Line line : lines) {
if (line.getNode().isArrayObjectElement()) {
@@ -270,14 +263,12 @@ public class GraphicFile extends JPanel {
}
}
-
private void removeAllClosingLabel() {
- for(Line line : lines) {
+ for (Line line : lines) {
line.removeClosingLabel();
}
}
-
public ArrayList getLines() {
return lines;
}
diff --git a/src/Line.java b/src/fr/sae/JSonInspector/Graphics/Line.java
similarity index 87%
rename from src/Line.java
rename to src/fr/sae/JSonInspector/Graphics/Line.java
index 9ed41c1..8b9b9d6 100644
--- a/src/Line.java
+++ b/src/fr/sae/JSonInspector/Graphics/Line.java
@@ -1,4 +1,8 @@
-package JsonInspector;
+package fr.sae.JSonInspector.Graphics;
+
+import fr.sae.JSonInspector.Graphics.MyJLabel;
+import fr.sae.JSonInspector.Graphics.MyJPanel;
+import fr.sae.JSonInspector.Storage.Node;
import java.awt.*;
@@ -9,14 +13,12 @@ public class Line extends MyJPanel {
private MyJLabel lastElement;
private boolean closingElement = false;
-
public Line(Node node, int depth) {
super();
this.node = node;
this.depth = depth;
}
-
public Line(Node node, String str, int depth) {
super();
this.add(new MyJLabel(str));
@@ -24,7 +26,6 @@ public class Line extends MyJPanel {
this.depth = depth;
}
-
public Line(Node node, String str, Color color, int depth) {
super();
this.add(new MyJLabel(str, color));
@@ -32,61 +33,51 @@ public class Line extends MyJPanel {
this.depth = depth;
}
-
public void add(String string) {
lastElement = new MyJLabel(string);
this.add(lastElement);
}
-
public void add(String string, Color color) {
lastElement = new MyJLabel(string, color);
this.add(lastElement);
}
-
public Node getNode() {
return node;
}
-
public int getDepth() {
return depth;
}
-
public boolean isShow() {
return show;
}
-
public void unfold() {
show = true;
}
-
public void retreat() {
show = false;
}
-
public void setClosingElement() {
closingElement = true;
}
-
public boolean isClosingElement() {
return closingElement;
}
-
public void removeClosingLabel() {
try {
if (lastElement.getText().equals("...]") || lastElement.getText().equals("...}")) {
this.remove(lastElement);
}
} catch (NullPointerException e) {
- //System.out.println("La ligne est vide");
+ // System.out.println("La ligne est vide");
}
}
}
diff --git a/src/MyJLabel.java b/src/fr/sae/JSonInspector/Graphics/MyJLabel.java
similarity index 63%
rename from src/MyJLabel.java
rename to src/fr/sae/JSonInspector/Graphics/MyJLabel.java
index 84589c8..c7e4235 100644
--- a/src/MyJLabel.java
+++ b/src/fr/sae/JSonInspector/Graphics/MyJLabel.java
@@ -1,4 +1,6 @@
-package JsonInspector;
+package fr.sae.JSonInspector.Graphics;
+
+import fr.sae.JSonInspector.Settings.Parameters;
import javax.swing.*;
import java.awt.*;
@@ -6,13 +8,13 @@ import java.awt.*;
public class MyJLabel extends JLabel {
public MyJLabel(String text, Color color) {
super(text);
- //this.setFont(Parameters.FILE_FONT);
+ // this.setFont(Parameters.FILE_FONT);
this.setForeground(color);
}
public MyJLabel(String text) {
super(text);
- //this.setFont(Parameters.FILE_FONT);
+ // this.setFont(Parameters.FILE_FONT);
this.setForeground(Parameters.DEFAULT_TEXT_COLOR);
}
}
diff --git a/src/MyJPanel.java b/src/fr/sae/JSonInspector/Graphics/MyJPanel.java
similarity index 86%
rename from src/MyJPanel.java
rename to src/fr/sae/JSonInspector/Graphics/MyJPanel.java
index e6ae9e1..c511617 100644
--- a/src/MyJPanel.java
+++ b/src/fr/sae/JSonInspector/Graphics/MyJPanel.java
@@ -1,4 +1,6 @@
-package JsonInspector;
+package fr.sae.JSonInspector.Graphics;
+
+import fr.sae.JSonInspector.Settings.Parameters;
import javax.swing.*;
import java.awt.*;
diff --git a/src/Main.java b/src/fr/sae/JSonInspector/Main.java
similarity index 89%
rename from src/Main.java
rename to src/fr/sae/JSonInspector/Main.java
index 5fcbf82..8b41e43 100644
--- a/src/Main.java
+++ b/src/fr/sae/JSonInspector/Main.java
@@ -1,5 +1,8 @@
-package JsonInspector;
+package fr.sae.JSonInspector;
+import fr.sae.JSonInspector.Exception.JsonSyntaxException;
+import fr.sae.JSonInspector.Graphics.Frame;
+import fr.sae.JSonInspector.Storage.Tree;
import java.io.*;
import java.net.MalformedURLException;
import java.net.URL;
@@ -8,7 +11,6 @@ public class Main {
public static void main(String[] args) {
if (args.length == 0) {
new Frame();
-
} else {
try {
URL url = new URL(args[0]);
@@ -44,7 +46,6 @@ public class Main {
return sb.toString();
}
-
public static String cleanFile(String file) {
char[] chars = file.toCharArray();
boolean inString = false, inValue = false;
@@ -72,13 +73,12 @@ public class Main {
return cleanedFile;
}
-
private static boolean isJsonSyntax(char character) {
boolean openingArray = character == '[', closingArray = character == ']';
boolean openingObject = character == '{', closingObject = character == '}';
boolean virgule = character == ',', deuxPoints = character == ':';
- if (openingArray||closingArray||openingObject||closingObject||virgule||deuxPoints) {
+ if (openingArray || closingArray || openingObject || closingObject || virgule || deuxPoints) {
return true;
}
return false;
diff --git a/src/Parameters.java b/src/fr/sae/JSonInspector/Settings/Parameters.java
similarity index 95%
rename from src/Parameters.java
rename to src/fr/sae/JSonInspector/Settings/Parameters.java
index e8bab69..9389731 100644
--- a/src/Parameters.java
+++ b/src/fr/sae/JSonInspector/Settings/Parameters.java
@@ -1,4 +1,4 @@
-package JsonInspector;
+package fr.sae.JSonInspector.Settings;
import java.awt.*;
diff --git a/src/Node.java b/src/fr/sae/JSonInspector/Storage/Node.java
similarity index 96%
rename from src/Node.java
rename to src/fr/sae/JSonInspector/Storage/Node.java
index d705da8..d583846 100644
--- a/src/Node.java
+++ b/src/fr/sae/JSonInspector/Storage/Node.java
@@ -1,15 +1,12 @@
-package JsonInspector;
+package fr.sae.JSonInspector.Storage;
-import java.awt.*;
import java.util.ArrayList;
-
public class Node {
private final ArrayList values = new ArrayList<>();
private final String name;
private final Type type;
-
public Node(String name, Type type) {
this.type = type;
if (type == Type.ELEMENT) {
@@ -19,9 +16,8 @@ public class Node {
}
}
-
private void findType(String value) {
- if (value.charAt(0) == '"' && value.charAt(value.length()-1) == '"') {
+ if (value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"') {
values.add(new Value(Tree.cleanOpeningExpression(value)));
return;
}
@@ -37,7 +33,6 @@ public class Node {
}
}
-
public void add(T value) {
if (value != null) {
if (value.getClass().equals(Node.class)) {
@@ -48,47 +43,38 @@ public class Node {
}
}
-
public Type getType() {
return type;
}
-
public String getName() {
return name;
}
-
public Value get(int index) {
return values.get(index);
}
-
public int getSize() {
return values.size();
}
-
public boolean isObject() {
return type == Type.OBJECT;
}
-
public boolean isArray() {
return type == Type.ARRAY;
}
-
public boolean isElement() {
return type == Type.ELEMENT;
}
-
public boolean isPair() {
return type == Type.PAIR;
}
-
public boolean isArrayObjectElement() {
boolean array = type == Type.ARRAY;
boolean object = type == Type.OBJECT;
@@ -101,7 +87,6 @@ public class Node {
return false;
}
-
@Override
public String toString() {
String string = name + " : ";
diff --git a/src/Other.java b/src/fr/sae/JSonInspector/Storage/Other.java
similarity index 82%
rename from src/Other.java
rename to src/fr/sae/JSonInspector/Storage/Other.java
index b7545a1..3a6bcca 100644
--- a/src/Other.java
+++ b/src/fr/sae/JSonInspector/Storage/Other.java
@@ -1,14 +1,12 @@
-package JsonInspector;
+package fr.sae.JSonInspector.Storage;
public class Other {
String value;
-
public Other(String value) {
this.value = value;
}
-
@Override
public String toString() {
return value;
diff --git a/src/Tree.java b/src/fr/sae/JSonInspector/Storage/Tree.java
similarity index 91%
rename from src/Tree.java
rename to src/fr/sae/JSonInspector/Storage/Tree.java
index 3f8b528..62303f5 100644
--- a/src/Tree.java
+++ b/src/fr/sae/JSonInspector/Storage/Tree.java
@@ -1,16 +1,17 @@
-package JsonInspector;
+package fr.sae.JSonInspector.Storage;
+
+import fr.sae.JSonInspector.Exception.JsonSyntaxException;
+import fr.sae.JSonInspector.Settings.Parameters;
import java.util.ArrayList;
public class Tree {
private Node firstNode;
-
public Tree(String file) throws JsonSyntaxException {
firstNode = parseElement(file);
}
-
private Node whichType(String element) throws JsonSyntaxException {
String[] keyValue = splitKeyValue(element);
@@ -33,7 +34,7 @@ public class Tree {
} else if (keyValue[0].equals("")) {
- if (keyValue[0].charAt(0) == '{' && keyValue[0].charAt(keyValue[0].length()-1) == '}') {
+ if (keyValue[0].charAt(0) == '{' && keyValue[0].charAt(keyValue[0].length() - 1) == '}') {
return parseElement(keyValue[0]);
} else {
throw new JsonSyntaxException();
@@ -44,7 +45,6 @@ public class Tree {
}
}
-
private Node parseArray(String name, String rawValues) throws JsonSyntaxException {
Node array = new Node(cleanOpeningExpression(name), Type.ARRAY);
ArrayList elements = splitList(rawValues);
@@ -67,7 +67,6 @@ public class Tree {
return array;
}
-
private Node parseObject(String name, String rawValues) throws JsonSyntaxException {
Node object = new Node(cleanOpeningExpression(name), Type.OBJECT);
ArrayList elements = splitList(rawValues);
@@ -79,7 +78,6 @@ public class Tree {
return object;
}
-
private Node parsePair(String name, String value) {
Node pair = new Node(cleanOpeningExpression(name), Type.PAIR);
pair.add(value);
@@ -87,7 +85,6 @@ public class Tree {
return pair;
}
-
private Node parseElement(String rawValues) throws JsonSyntaxException {
Node element = new Node("", Type.ELEMENT);
ArrayList elements = splitList(rawValues);
@@ -99,15 +96,13 @@ public class Tree {
return element;
}
-
public static String cleanOpeningExpression(String strToClean) {
StringBuilder cleanedString = new StringBuilder(strToClean);
cleanedString.deleteCharAt(0);
- cleanedString.deleteCharAt(cleanedString.length()-1);
+ cleanedString.deleteCharAt(cleanedString.length() - 1);
return cleanedString.toString();
}
-
private ArrayList splitList(String listToSplit) {
char[] chars = cleanOpeningExpression(listToSplit).toCharArray();
int depth = 0;
@@ -132,7 +127,6 @@ public class Tree {
return elements;
}
-
private String[] splitKeyValue(String expressionToSplit) {
boolean inKey = true;
char[] chars = expressionToSplit.toCharArray();
@@ -156,15 +150,14 @@ public class Tree {
}
value = buffer;
- return new String[] {key, value};
+ return new String[] { key, value };
}
-
public static String printTree(Node node, int depth) {
String line = "", indentation = "";
- //créé l'indentation de la bonne taille en fonction de la
- //profondeur dans l'arbre
+ // créé l'indentation de la bonne taille en fonction de la
+ // profondeur dans l'arbre
for (int i = 0; i < depth; i++) {
indentation += Parameters.CONSOLE_INDENTATION;
}
@@ -175,21 +168,19 @@ public class Tree {
line += indentation + node.getName();
}
-
if (node.isObject() || node.isElement()) {
line += printObjectElement(node, depth, indentation);
- } else if (node.isPair()){
+ } else if (node.isPair()) {
line += printPair(node);
- } else if (node.isArray()){
+ } else if (node.isArray()) {
line += printArray(node, depth, indentation);
}
return line;
}
-
private static String callNextNodes(Node node, int depth) {
String line = "";
@@ -206,7 +197,6 @@ public class Tree {
return line;
}
-
private static String printPair(Node node) {
String line = "";
@@ -224,7 +214,6 @@ public class Tree {
return line;
}
-
private static String printObjectElement(Node node, int depth, String indentation) {
String line = "";
@@ -244,7 +233,6 @@ public class Tree {
return line;
}
-
private static String printArray(Node node, int depth, String indentation) {
String line = "";
line += ": [";
@@ -261,11 +249,11 @@ public class Tree {
line += "\n" + printTree((Node) node.get(i).getValue(), depth + 1);
} else {
line += "\n" + indentation + Parameters.CONSOLE_INDENTATION;
- if (node.get(i).isString()) {
- line += "\"" + node.get(i).getValue() + "\"";
- } else {
- line += node.get(i).getValue();
- }
+ if (node.get(i).isString()) {
+ line += "\"" + node.get(i).getValue() + "\"";
+ } else {
+ line += node.get(i).getValue();
+ }
}
// si la valeur n'est pas la dernière alors on lui ajoute une virgule
@@ -280,13 +268,11 @@ public class Tree {
return line;
}
-
@Override
public String toString() {
return printTree(firstNode, 0);
}
-
public Node getFirstNode() {
return firstNode;
}
diff --git a/src/Type.java b/src/fr/sae/JSonInspector/Storage/Type.java
similarity index 61%
rename from src/Type.java
rename to src/fr/sae/JSonInspector/Storage/Type.java
index ecd7ada..a6f87a3 100644
--- a/src/Type.java
+++ b/src/fr/sae/JSonInspector/Storage/Type.java
@@ -1,4 +1,4 @@
-package JsonInspector;
+package fr.sae.JSonInspector.Storage;
public enum Type {
OBJECT, ELEMENT, ARRAY, PAIR, NULL
diff --git a/src/Value.java b/src/fr/sae/JSonInspector/Storage/Value.java
similarity index 89%
rename from src/Value.java
rename to src/fr/sae/JSonInspector/Storage/Value.java
index 899ec48..304670e 100644
--- a/src/Value.java
+++ b/src/fr/sae/JSonInspector/Storage/Value.java
@@ -1,19 +1,16 @@
-package JsonInspector;
+package fr.sae.JSonInspector.Storage;
-public class Value {
+public class Value {
private T value;
-
public Value(T value) {
this.value = value;
}
-
public T getValue() {
return value;
}
-
public boolean isObjectOrArray() {
if (value.getClass().equals(Node.class)) {
Node node = (Node) value;
@@ -27,17 +24,14 @@ public class Value {
}
}
-
public boolean isNode() {
return value.getClass().equals(Node.class);
}
-
- public boolean isString () {
+ public boolean isString() {
return value.getClass().equals(String.class);
}
-
public boolean isNumber() {
return value.getClass().equals(Integer.class) || value.getClass().equals(Double.class);
}