Transférer les fichiers vers 'src/fr/sae/JSonInspector/Storage'

This commit is contained in:
Romain BESSON 2023-01-16 00:10:15 +01:00
parent 285c936322
commit 936e74f10b
5 changed files with 608 additions and 541 deletions
src/fr/sae/JSonInspector/Storage

@ -1,100 +1,148 @@
package fr.sae.JSonInspector.Storage; package JsonInspector.Storage;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List;
public class Node {
private final ArrayList<Value> values = new ArrayList<>();
private final String name; public class Node {
private final Type type; private final List<Value> values = new ArrayList<>();
private final String name;
public Node(String name, Type type) { private final Type type;
this.type = type;
if (type == Type.ELEMENT) {
this.name = ""; /**
} else { *
this.name = name; * @param name le nom du noeud
} * @param type le type du noeud
} */
public Node(String name, Type type) {
private void findType(String value) { this.type = type;
if (value.charAt(0) == '"' && value.charAt(value.length() - 1) == '"') { if (type == Type.ELEMENT) {
values.add(new Value<String>(Tree.cleanOpeningExpression(value))); this.name = "";
return; } else {
} this.name = name;
}
try { }
values.add(new Value<Integer>(Integer.parseInt(value)));
} catch (NumberFormatException nfeInt) {
try { /**
values.add(new Value<Double>(Double.parseDouble(value))); * Détermine le type de la chaîne de caractère passé en argument
} catch (NumberFormatException nfeDouble) { * @param value la valeur à classifier
values.add(new Value<Other>(new Other(value))); */
} private void findType(String value) {
} if (value.charAt(0) == '"' && value.charAt(value.length()-1) == '"') {
} values.add(new Value<String>(Tree.cleanOpeningExpression(value)));
return;
public <T> void add(T value) { }
if (value != null) {
if (value.getClass().equals(Node.class)) { try {
values.add(new Value<T>(value)); values.add(new Value<Integer>(Integer.parseInt(value)));
} else { } catch (NumberFormatException nfeInt) {
findType((String) value); try {
} values.add(new Value<Double>(Double.parseDouble(value)));
} } catch (NumberFormatException nfeDouble) {
} values.add(new Value<Other>(new Other(value)));
}
public Type getType() { }
return type; }
}
public String getName() { /**
return name; * Ajoute une valeur au noeud
} * @param value la valeur à ajouter
* @param <T> le type de la valeur à ajouter
public Value get(int index) { */
return values.get(index); public <T> void add(T value) {
} if (value != null) {
if (value.getClass().equals(Node.class)) {
public int getSize() { values.add(new Value<T>(value));
return values.size(); } else {
} findType((String) value);
}
public boolean isObject() { }
return type == Type.OBJECT; }
}
public boolean isArray() { /**
return type == Type.ARRAY; *
} * @return le type du noeud
*/
public boolean isElement() { public Type getType() {
return type == Type.ELEMENT; return type;
} }
public boolean isPair() {
return type == Type.PAIR; /**
} *
* @return le nom du noeud
public boolean isArrayObjectElement() { */
boolean array = type == Type.ARRAY; public String getName() {
boolean object = type == Type.OBJECT; return name;
boolean element = type == Type.ELEMENT; }
if (array || object || element) {
return true; /**
} * Retourne la valeur contenue à l'index spécifié
* @param index l'index de la valeur
return false; * @return la valeur trouvée
} */
public Value get(int index) {
@Override return values.get(index);
public String toString() { }
String string = name + " : ";
for (int i = 0; i < values.size(); i++) { /**
string += values.get(i) + ", "; * retourne le nombre de valeurs du noeud
} * @return
*/
return string; 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;
}
/**
* Test si l'objet est du type 'ELEMENT' ou 'OBJECT'
* @return
*/
public boolean isArrayObjectElement() {
boolean array = type == Type.ARRAY;
boolean object = type == Type.OBJECT;
boolean element = type == Type.ELEMENT;
if (array || object || element) {
return true;
}
return false;
}
@Override
public String toString() {
String string = name + " : ";
for (int i = 0; i < values.size(); i++) {
string += values.get(i) + ", ";
}
return string;
}
}

@ -1,14 +1,19 @@
package fr.sae.JSonInspector.Storage; package JsonInspector.Storage;
public class Other {
String value; /**
* Un type créé pour les valeurs qui ne sont pas de type String, Double ou Integer (e type est un String dans les faits).
public Other(String value) { */
this.value = value; public class Other {
} String value;
@Override public Other(String value) {
public String toString() { this.value = value;
return value; }
}
}
@Override
public String toString() {
return value;
}
}

File diff suppressed because it is too large Load Diff

@ -1,5 +1,9 @@
package fr.sae.JSonInspector.Storage; package JsonInspector.Storage;
public enum Type {
OBJECT, ELEMENT, ARRAY, PAIR, NULL /**
} * Un type énuméré contenant tous les types possibles de noeud
*/
public enum Type {
OBJECT, ELEMENT, ARRAY, PAIR, NULL
}

@ -1,38 +1,48 @@
package fr.sae.JSonInspector.Storage; package JsonInspector.Storage;
public class Value<T> { /**
private T value; * Représente une valeur
* @param <T> le type de la valeur
public Value(T value) { */
this.value = value; public class Value <T> {
} private T value;
public T getValue() {
return value; public Value(T value) {
} this.value = value;
}
public boolean isObjectOrArray() {
if (value.getClass().equals(Node.class)) {
Node node = (Node) value; public T getValue() {
if (node.getType() == Type.OBJECT || node.getType() == Type.ARRAY) { return value;
return true; }
} else {
return false;
} public boolean isObjectOrArray() {
} else { if (value.getClass().equals(Node.class)) {
return false; Node node = (Node) value;
} if (node.getType() == Type.OBJECT || node.getType() == Type.ARRAY) {
} return true;
} else {
public boolean isNode() { return false;
return value.getClass().equals(Node.class); }
} } else {
return false;
public boolean isString() { }
return value.getClass().equals(String.class); }
}
public boolean isNumber() { public boolean isNode() {
return value.getClass().equals(Integer.class) || value.getClass().equals(Double.class); return value.getClass().equals(Node.class);
} }
}
public boolean isString () {
return value.getClass().equals(String.class);
}
public boolean isNumber() {
return value.getClass().equals(Integer.class) || value.getClass().equals(Double.class);
}
}