|
@@ -0,0 +1,96 @@
|
|
|
+package migl.lisp.util;
|
|
|
+
|
|
|
+import java.math.BigInteger;
|
|
|
+
|
|
|
+import migl.lisp.LispBoolean;
|
|
|
+
|
|
|
+public class LispElement {
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Le conteneur de la valeur de l'element
|
|
|
+ */
|
|
|
+ private final LispElementValue value;
|
|
|
+
|
|
|
+ /* --- Constructeurs privés des differents elements --- */
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creation d'un element de type BigInt
|
|
|
+ * @param val
|
|
|
+ */
|
|
|
+ private LispElement(BigInteger val) {
|
|
|
+ this.value = new LispElementValue<>(val);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creation d'un element de type double
|
|
|
+ * @param val
|
|
|
+ */
|
|
|
+ private LispElement(double val) {
|
|
|
+ this.value = new LispElementValue<>(val);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creation d'un element de type LispBoolean
|
|
|
+ * @param val
|
|
|
+ */
|
|
|
+ private LispElement(LispBoolean val) {
|
|
|
+ this.value = new LispElementValue<>(val);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Creation d'un element de type String
|
|
|
+ * @param val
|
|
|
+ */
|
|
|
+ private LispElement(String val) {
|
|
|
+ this.value = new LispElementValue<>(val);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Retourne le conteneur de l'element
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public LispElementValue get() {
|
|
|
+ return this.value;
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Parse un element
|
|
|
+ * @param elt
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public static LispElement valueOf(String elt) {
|
|
|
+ try {
|
|
|
+ return new LispElement(new BigInteger(elt));
|
|
|
+ } catch(NumberFormatException ex) {
|
|
|
+ //Rien
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return new LispElement(Double.valueOf(elt));
|
|
|
+ } catch(NumberFormatException ex) {
|
|
|
+ //Rien
|
|
|
+ }
|
|
|
+ try {
|
|
|
+ return new LispElement(LispBoolean.valueOf(elt));
|
|
|
+ } catch(IllegalArgumentException ex) {
|
|
|
+ //Rien
|
|
|
+ }
|
|
|
+ return new LispElement(elt);
|
|
|
+ }
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Conteneur de la valeur d'un element
|
|
|
+ * @author Arthur Brandao
|
|
|
+ *
|
|
|
+ * @param <E> Le type de l'element
|
|
|
+ */
|
|
|
+ public class LispElementValue<E> {
|
|
|
+
|
|
|
+ public final E value;
|
|
|
+
|
|
|
+ public LispElementValue(E val){
|
|
|
+ this.value = val;
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+}
|