diff --git a/src/Main.java b/src/Main.java new file mode 100644 index 0000000..b66f1a3 --- /dev/null +++ b/src/Main.java @@ -0,0 +1,17 @@ +import expression.Expression; +import expression.Tree; + +/** + * Created by xawirses on 29/03/17. + */ +public class Main { + public static void main(String[] args) { + Expression e = new Expression(); + e.negExpressionPrefixe(); + System.out.println(e.getExpressionPrefixe()); + System.out.println(); + + Tree treeExpression = new Tree(e.getExpressionPrefixe()); + treeExpression.display(); + } +} diff --git a/src/Node.java b/src/Node.java deleted file mode 100644 index edd5e62..0000000 --- a/src/Node.java +++ /dev/null @@ -1,61 +0,0 @@ -/** - * Created by azael on 20/03/17. - */ -public class Node { - - private char node; - - private Node father; - private Node leftChild; - private Node rigthChild; - private int lvl; - - private int pos = 0; - - Node(Node father, Node leftChild, Node rightChild, char name, int lvl){ - this.node = name; - this.father = father; - this.leftChild = leftChild; - this.rigthChild = rightChild; - this.lvl = lvl; - } - - public void setLeftChild(Node leftChild) { this.leftChild = leftChild; } - public void setRigthChild(Node rigthChild) { this.rigthChild = rigthChild; } - - public void setFather(Node father) { - this.father = father; - } - - public void display() { - System.out.println(node); - } - - public int getLvl() { - return lvl; - } - - public Node getLeftChild() { - return leftChild; - } - - public Node getRigthChild() { - return rigthChild; - } - - public char getNode() { - return node; - } - - public Node getFather() { - return father; - } - - public int getPos() { - return pos; - } - - public void setPos(int pos) { - this.pos = pos; - } -} diff --git a/src/Expression.java b/src/expression/Expression.java similarity index 90% rename from src/Expression.java rename to src/expression/Expression.java index a30b87d..fd39217 100644 --- a/src/Expression.java +++ b/src/expression/Expression.java @@ -1,3 +1,5 @@ +package expression; + import java.io.BufferedReader; import java.io.IOException; import java.io.InputStreamReader; @@ -102,10 +104,6 @@ public class Expression { expressionPrefixe = reverseExpression(reversePrefix); } - public String getExpression() { - return expression; - } - public String getExpressionPrefixe() { return expressionPrefixe; } @@ -113,14 +111,4 @@ public class Expression { public void negExpressionPrefixe (){ expressionPrefixe = "!" + expressionPrefixe; } - - public static void main(String[] args) { - Expression e = new Expression(); - e.negExpressionPrefixe(); - System.out.println(e.getExpressionPrefixe()); - System.out.println(); - - Tree t = new Tree(e.getExpressionPrefixe()); - t.display(); - } } diff --git a/src/expression/Node.java b/src/expression/Node.java new file mode 100644 index 0000000..b9a7875 --- /dev/null +++ b/src/expression/Node.java @@ -0,0 +1,36 @@ +package expression; + +/** + * Created by azael on 20/03/17. + */ +public class Node { + + private char node; + + private Node leftChild; + private Node rigthChild; + private int lvl; + + Node(Node leftChild, Node rightChild, char name, int lvl){ + this.node = name; + this.leftChild = leftChild; + this.rigthChild = rightChild; + this.lvl = lvl; + } + + public void display() { + System.out.println(node); + } + + public int getLvl() { + return lvl; + } + + public Node getLeftChild() { + return leftChild; + } + + public Node getRigthChild() { + return rigthChild; + } +} diff --git a/src/Operator.java b/src/expression/Operator.java similarity index 90% rename from src/Operator.java rename to src/expression/Operator.java index a67a124..d0ff3f1 100644 --- a/src/Operator.java +++ b/src/expression/Operator.java @@ -1,3 +1,5 @@ +package expression; + /** * Created by xawirses on 28/02/17. */ diff --git a/src/Tree.java b/src/expression/Tree.java similarity index 67% rename from src/Tree.java rename to src/expression/Tree.java index d90a95b..25cce97 100644 --- a/src/Tree.java +++ b/src/expression/Tree.java @@ -1,3 +1,7 @@ +package expression; + +import expression.Expression; + /** * Created by azael on 20/03/17. */ @@ -6,7 +10,7 @@ public class Tree { private Node root; private String exp; - Tree (String exp){ + public Tree(String exp){ this.exp = exp; root = tree(0); } @@ -17,22 +21,16 @@ public class Tree { if(Expression.isOperator(item)) { if (item == '!'){ Node fils = tree(pos+1); - Node f = new Node(null, fils, null, item, 1+fils.getLvl()); - fils.setPos(1); - fils.setFather(f); + Node f = new Node(fils, null, item, 1+fils.getLvl()); return f; } else { Node filsG = tree(pos+1); Node filsD = tree(pos+filsG.getLvl()+1); - Node f = new Node(null, filsG, filsD, item, filsG.getLvl() + filsD.getLvl()+1); - filsG.setPos(1); - filsD.setPos(2); - filsG.setFather(f); - filsD.setFather(f); + Node f = new Node(filsG, filsD, item, filsG.getLvl() + filsD.getLvl()+1); return f; } } else { - return new Node(null, null, null, item, 1); + return new Node(null, null, item, 1); } } diff --git a/src/statement/World.java b/src/statement/World.java new file mode 100644 index 0000000..933b54d --- /dev/null +++ b/src/statement/World.java @@ -0,0 +1,19 @@ +package statement; + +import expression.Node; + +import java.util.ArrayList; +import java.util.Collection; + +/** + * Created by xawirses on 29/03/17. + */ +public class World { + private String name; + private Collection expressions = new ArrayList<>(); + private Collection involved = new ArrayList<>(); + + public World(String name) { + this.name = name; + } +}