Quellcode durchsuchen

Refactoring LispElement

Arthur Brandao vor 6 Jahren
Ursprung
Commit
af0a91d519

+ 9 - 1
src/migl/lisp/LispElement.java

@@ -22,7 +22,7 @@ public class LispElement {
 	/**
 	 * La valeur de l'element
 	 */
-	public final Object value;
+	private final Object value;
 
 	/**
 	 * Constructeur privée pour construire un element à partir de valueOf
@@ -34,6 +34,14 @@ public class LispElement {
 		cache.put(val, this);
 	}
 	
+	/**
+	 * Retourne la valeur de l'element lisp
+	 * @return
+	 */
+	public Object getValue() {
+		return this.value;
+	}
+	
 	/**
 	 * Retourne la valeur d'un element sous forme d'entier
 	 * 

+ 2 - 2
src/migl/lisp/LispEval.java

@@ -152,7 +152,7 @@ public class LispEval {
 			BigInteger resultInt = new BigInteger("0");
 			while(!lisp.isEmpty()){
 				LispElement eltInt = eval.getElement(lisp.car());
-				if(eltInt.value.getClass() != BigInteger.class) break;
+				if(eltInt.getValue().getClass() != BigInteger.class) break;
 				resultInt = resultInt.add(eltInt.toInt());
 				lisp = lisp.cdr();
 			}
@@ -171,7 +171,7 @@ public class LispEval {
 			BigInteger resultInt = new BigInteger("1");
 			while(!lisp.isEmpty()){
 				LispElement eltInt = eval.getElement(lisp.car());
-				if(eltInt.value.getClass() != BigInteger.class) break;
+				if(eltInt.getValue().getClass() != BigInteger.class) break;
 				resultInt = resultInt.multiply(eltInt.toInt());
 				lisp = lisp.cdr();
 			}

+ 2 - 2
src/migl/lisp/LispParser.java

@@ -155,7 +155,7 @@ public class LispParser {
 			if(this.explode.size() > 0) {
 				throw new LispError("Invalid Format");
 			}
-			return LispElement.valueOf(val).value;
+			return LispElement.valueOf(val).getValue();
 		}
 	}
 	
@@ -205,7 +205,7 @@ public class LispParser {
 			if("(".equals(val)) {
 				list = list.append(this.parseList());
 			} else {
-				list = list.append(LispElement.valueOf(val).value);
+				list = list.append(LispElement.valueOf(val).getValue());
 			}
 			val = this.explode.poll();
 		}

+ 1 - 1
src/migl/lisp/operator/ConsOperator.java

@@ -31,7 +31,7 @@ public class ConsOperator implements LispOperator {
 			//Recup + evaluation de la liste
 			String listStr = eval.getElement(lisp.cdr().car()).toString();
 			LispList list = LispList.valueOf(listStr);
-			list.prepend(eval.getElement(lisp.car()).value);
+			list.prepend(eval.getElement(lisp.car()).getValue());
 			return LispElement.generate(list);
 		} else {
 			LispElement elt = eval.getElement(lisp.car());

+ 1 - 1
src/migl/lisp/operator/MinMaxOperator.java

@@ -23,7 +23,7 @@ public class MinMaxOperator implements LispOperator {
 			//Parcours les elements suivants
 			while(!lisp.isEmpty()) {
 				elt = eval.getElement(lisp.car());
-	            if(elt.value.getClass() != BigInteger.class) break;
+	            if(elt.getValue().getClass() != BigInteger.class) break;
 	            switch(operator) {
 					case "max":
 						res = res.max(elt.toInt());