diff --git a/ExpMath/nb-configuration.xml b/ExpMath/nb-configuration.xml
new file mode 100644
index 0000000..98cd079
--- /dev/null
+++ b/ExpMath/nb-configuration.xml
@@ -0,0 +1,18 @@
+
+
+
+
+
+ gpl30
+
+
diff --git a/ExpMath/src/main/java/net/cofares/model/Add.java b/ExpMath/src/main/java/net/cofares/model/Add.java
index 01a6f71..78ad2a4 100644
--- a/ExpMath/src/main/java/net/cofares/model/Add.java
+++ b/ExpMath/src/main/java/net/cofares/model/Add.java
@@ -25,17 +25,17 @@ private Add(Expression e1, Expression e2) {
}
@Override
public Integer evalNum() {
- return en.evalNum(this);
+ return en.eval(this);
}
@Override
public Expression eval() {
- return Const.create(e1.evalNum()+e2.evalNum());
+ return e.eval(this);
}
@Override
public String show() {
- return "(" + e1.show() + "+" + e2.show() + ")" ;
+ return es.eval(this);
}
}
diff --git a/ExpMath/src/main/java/net/cofares/model/Const.java b/ExpMath/src/main/java/net/cofares/model/Const.java
index 2750b47..424a362 100644
--- a/ExpMath/src/main/java/net/cofares/model/Const.java
+++ b/ExpMath/src/main/java/net/cofares/model/Const.java
@@ -20,17 +20,17 @@ private Const(Integer i){
@Override
public Expression eval() {
- return this;
+ return e.eval(this);
}
@Override
public String show() {
- return "Const:"+getI();
+ return es.eval(this);
}
@Override
public Integer evalNum() {
- return en.evalNum(this);
+ return en.eval(this);
}
public static void main(String args[]) {
diff --git a/ExpMath/src/main/java/net/cofares/model/EvalNum.java b/ExpMath/src/main/java/net/cofares/model/EvalNum.java
deleted file mode 100644
index 53ae630..0000000
--- a/ExpMath/src/main/java/net/cofares/model/EvalNum.java
+++ /dev/null
@@ -1,24 +0,0 @@
-/*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
-package net.cofares.model;
-
-/**
- * Le visiteur EvalNum
- * @author Acer
- */
-public class EvalNum {
- Integer evalNum(Const c){
- return c.getI();
- }
-
- Integer evalNum(Add a){
- return a.e1.evalNum()+a.e2.evalNum();
- }
-
- Integer evalNum(Sous a){
- return a.e1.evalNum()-a.e2.evalNum();
- }
-}
diff --git a/ExpMath/src/main/java/net/cofares/model/Expression.java b/ExpMath/src/main/java/net/cofares/model/Expression.java
index 928eb88..6be78b0 100644
--- a/ExpMath/src/main/java/net/cofares/model/Expression.java
+++ b/ExpMath/src/main/java/net/cofares/model/Expression.java
@@ -1,5 +1,9 @@
package net.cofares.model;
+import net.cofares.visiteur.eval.EvalNum;
+import net.cofares.visiteur.eval.EvalShow;
+import net.cofares.visiteur.eval.EvalToExp;
+
/**
* La grammaire
*
@@ -27,7 +31,9 @@
* @author Pascal Fares
*/
public abstract class Expression {
- static EvalNum en = new EvalNum(); //Le visiteur Eval NUM TODO: faire que tous les visiteur evaluateur soit une startegie
+ static EvalNum en = new EvalNum(); //Les visiteur
+ static EvalToExp e = new EvalToExp();
+ static EvalShow es = new EvalShow();
// à injecter apr un setter, à la création une evaluateur par defaut.
//Factory Expression create : style visiteur
diff --git a/ExpMath/src/main/java/net/cofares/model/ExpressionB.java b/ExpMath/src/main/java/net/cofares/model/ExpressionB.java
index b9c77a6..6466c44 100644
--- a/ExpMath/src/main/java/net/cofares/model/ExpressionB.java
+++ b/ExpMath/src/main/java/net/cofares/model/ExpressionB.java
@@ -5,14 +5,46 @@
*/
package net.cofares.model;
+import net.cofares.visiteur.eval.EvalNum;
+import net.cofares.visiteur.eval.EvalShow;
+import net.cofares.visiteur.eval.EvalToExp;
+
/**
* omolememte composition, Abstract Factory + template
* @author Acer
*/
public abstract class ExpressionB extends Expression{
- Expression e1;
- Expression e2;
+ /**
+ * @return the e1
+ */
+ public Expression getE1() {
+ return e1;
+ }
+
+ /**
+ * @param e1 the e1 to set
+ */
+ public void setE1(Expression e1) {
+ this.e1 = e1;
+ }
+
+ /**
+ * @return the e2
+ */
+ public Expression getE2() {
+ return e2;
+ }
+
+ /**
+ * @param e2 the e2 to set
+ */
+ public void setE2(Expression e2) {
+ this.e2 = e2;
+ }
+
+ protected Expression e1;
+ protected Expression e2;
/**
@@ -25,6 +57,9 @@ public abstract class ExpressionB extends Expression{
*/
public static ExpressionB create(String op, Expression e1, Expression e2) {
en = new EvalNum(); //TODO le passer en injection (c' est en fait une tratégie d'évaluation
+ e=new EvalToExp();
+ es=new EvalShow();
+
if (op.equals("+")) {
return Add.create(e1, e2);
} else if (op.equals("-")) {
diff --git a/ExpMath/src/main/java/net/cofares/model/Sous.java b/ExpMath/src/main/java/net/cofares/model/Sous.java
index 194eece..0986ffa 100644
--- a/ExpMath/src/main/java/net/cofares/model/Sous.java
+++ b/ExpMath/src/main/java/net/cofares/model/Sous.java
@@ -23,19 +23,20 @@ private Sous(Expression e1, Expression e2) {
this.e1=e1;
this.e2=e2;
}
+
@Override
public Integer evalNum() {
- return en.evalNum(this);
+ return en.eval(this);
}
@Override
public Expression eval() {
- return Const.create(e1.evalNum()-e2.evalNum());
+ return e.eval(this);
}
@Override
public String show() {
- return "(" + e1.show() + "-" + e2.show() + ")" ;
+ return es.eval(this);
}
}
diff --git a/ExpMath/src/main/java/net/cofares/visiteur/eval/Eval.java b/ExpMath/src/main/java/net/cofares/visiteur/eval/Eval.java
new file mode 100644
index 0000000..c7008fd
--- /dev/null
+++ b/ExpMath/src/main/java/net/cofares/visiteur/eval/Eval.java
@@ -0,0 +1,35 @@
+/*
+ * Copyright (C) 2019 pfares
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package net.cofares.visiteur.eval;
+
+import net.cofares.model.Add;
+import net.cofares.model.Const;
+import net.cofares.model.Sous;
+
+/**
+ *
+ * @author pfares
+ */
+public interface Eval {
+
+ T eval(Const c);
+
+ T eval(Add a);
+
+ T eval(Sous a);
+
+}
diff --git a/ExpMath/src/main/java/net/cofares/visiteur/eval/EvalNum.java b/ExpMath/src/main/java/net/cofares/visiteur/eval/EvalNum.java
new file mode 100644
index 0000000..350d0b9
--- /dev/null
+++ b/ExpMath/src/main/java/net/cofares/visiteur/eval/EvalNum.java
@@ -0,0 +1,31 @@
+/*
+ * To change this license header, choose License Headers in Project Properties.
+ * To change this template file, choose Tools | Templates
+ * and open the template in the editor.
+ */
+package net.cofares.visiteur.eval;
+
+import net.cofares.model.Add;
+import net.cofares.model.Const;
+import net.cofares.model.Sous;
+
+/**
+ * Le visiteur EvalNum
+ * @author Pascal Fares
+ */
+public class EvalNum implements Eval {
+ @Override
+ public Integer eval(Const c){
+ return c.getI();
+ }
+
+ @Override
+ public Integer eval(Add a){
+ return a.getE1().evalNum()+a.getE2().evalNum();
+ }
+
+ @Override
+ public Integer eval(Sous a){
+ return a.getE1().evalNum()-a.getE2().evalNum();
+ }
+}
diff --git a/ExpMath/src/main/java/net/cofares/visiteur/eval/EvalShow.java b/ExpMath/src/main/java/net/cofares/visiteur/eval/EvalShow.java
new file mode 100644
index 0000000..4ef4594
--- /dev/null
+++ b/ExpMath/src/main/java/net/cofares/visiteur/eval/EvalShow.java
@@ -0,0 +1,44 @@
+/*
+ * Copyright (C) 2019 pfares
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package net.cofares.visiteur.eval;
+
+import net.cofares.model.Add;
+import net.cofares.model.Const;
+import net.cofares.model.Sous;
+
+/**
+ * LE visiteur evalShow
+ * @author pfares
+ */
+public class EvalShow implements Eval {
+
+ @Override
+ public String eval(Const c) {
+ return "Const:"+c.getI();
+ }
+
+ @Override
+ public String eval(Add a) {
+ return "("+a.getE1().show()+"+"+a.getE2().show()+ ")";
+ }
+
+ @Override
+ public String eval(Sous a) {
+ return "("+a.getE1().show()+"-"+a.getE2().show()+ ")";
+ }
+
+}
diff --git a/ExpMath/src/main/java/net/cofares/visiteur/eval/EvalToExp.java b/ExpMath/src/main/java/net/cofares/visiteur/eval/EvalToExp.java
new file mode 100644
index 0000000..eaefdb5
--- /dev/null
+++ b/ExpMath/src/main/java/net/cofares/visiteur/eval/EvalToExp.java
@@ -0,0 +1,45 @@
+/*
+ * Copyright (C) 2019 pfares
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation, either version 3 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program. If not, see .
+ */
+package net.cofares.visiteur.eval;
+
+import net.cofares.model.Add;
+import net.cofares.model.Const;
+import net.cofares.model.Expression;
+import net.cofares.model.Sous;
+
+/**
+ * LE visiteur eval
+ * @author pfares
+ */
+public class EvalToExp implements Eval {
+
+ @Override
+ public Expression eval(Const c) {
+ return c;
+ }
+
+ @Override
+ public Expression eval(Add a) {
+ return Const.create(a.getE1().evalNum()+a.getE2().evalNum());
+ }
+
+ @Override
+ public Expression eval(Sous a) {
+ return Const.create(a.getE1().evalNum()-a.getE2().evalNum());
+ }
+
+}