From 6f05cf681fcfbc37481e9f6d5db3ffac5a9454b2 Mon Sep 17 00:00:00 2001 From: Marc Baloup Date: Fri, 26 Dec 2014 16:56:39 +0100 Subject: [PATCH] Nettoyage de la classe JArithmeticInterpreter --- .../java/util/JArithmeticInterpreter.java | 191 +++++++++--------- 1 file changed, 97 insertions(+), 94 deletions(-) diff --git a/src/net/mc_pandacraft/java/util/JArithmeticInterpreter.java b/src/net/mc_pandacraft/java/util/JArithmeticInterpreter.java index add9378..bc91dc9 100644 --- a/src/net/mc_pandacraft/java/util/JArithmeticInterpreter.java +++ b/src/net/mc_pandacraft/java/util/JArithmeticInterpreter.java @@ -449,16 +449,19 @@ public class JArithmeticInterpreter { //.................................................................................... Write_Tree + public String writeTree() { + StringBuffer sb = new StringBuffer(); + writeTree(sb); + return sb.toString(); + } + + + + private void writeTree(StringBuffer string) { boolean parenthese=false; switch(mOperator) { - case -2: - string.append('y'); - break; - case -1: - string.append('x'); - break; case 0: string.append(mValue); break; @@ -550,7 +553,7 @@ public class JArithmeticInterpreter { string.append(')'); break; case 9: - string.append("�("); + string.append("sqrt("); fg.writeTree(string); string.append(')'); break; @@ -605,7 +608,7 @@ public class JArithmeticInterpreter { signe=-1; i++; } - if (chaine.charAt(i)=='�') return signe*Math.PI; + if (chaine.charAt(i)=='�') return signe*Math.PI; // TODO changer le caractère non reconnu while (i47 && chaine.charAt(i)<58) { temp=temp*10+(chaine.charAt(i)-48); @@ -626,102 +629,102 @@ public class JArithmeticInterpreter { //.................................................................................... FindOperator private static void FindOperator(VariableInt oper,VariableInt esp,StringBuffer chaine,int pos) { - switch(chaine.charAt(pos)) { - case 'a': - switch(chaine.charAt(pos+1)) { - case 'b': - esp.mValue=3; - oper.mValue=10; - break; - case 'c': - esp.mValue=4; - oper.mValue=15; - break; - case 's': - esp.mValue=4; - oper.mValue=14; - break; - case 't': - esp.mValue=4; - oper.mValue=16; - break; - } - break; - case 'c': - if (chaine.charAt(pos+1)=='h') { - esp.mValue=2; - oper.mValue=18; - } - else if ((chaine.charAt(pos+1)=='o') && (chaine.charAt(pos+2)=='s')) { - if (chaine.charAt(pos+3)=='h') { - esp.mValue=4; + switch(chaine.charAt(pos)) { + case 'a': + switch(chaine.charAt(pos+1)) { + case 'b': + esp.mValue=3; + oper.mValue=10; + break; + case 'c': + esp.mValue=4; + oper.mValue=15; + break; + case 's': + esp.mValue=4; + oper.mValue=14; + break; + case 't': + esp.mValue=4; + oper.mValue=16; + break; + } + break; + case 'c': + if (chaine.charAt(pos+1)=='h') { + esp.mValue=2; oper.mValue=18; } - else { - esp.mValue=3; - oper.mValue=12; + else if ((chaine.charAt(pos+1)=='o') && (chaine.charAt(pos+2)=='s')) { + if (chaine.charAt(pos+3)=='h') { + esp.mValue=4; + oper.mValue=18; + } + else { + esp.mValue=3; + oper.mValue=12; + } } - } - break; - case 'e': - if ((chaine.charAt(pos+1)=='x') && (chaine.charAt(pos+2)=='p')) { - esp.mValue=3; - oper.mValue=6; - } - else oper.mValue=-10; - break; - case 'l': - if (chaine.charAt(pos+1)=='n') { - esp.mValue=2; - oper.mValue=7; - } - else if ((chaine.charAt(pos+1)=='o') && (chaine.charAt(pos+2)=='g')){ - esp.mValue=3; - oper.mValue=8; - } - else oper.mValue=-10; - break; - case 's': - if (chaine.charAt(pos+1)=='h') { - esp.mValue=2; - oper.mValue=17; - } - else if (chaine.charAt(pos+1)=='q') { - esp.mValue=4; - oper.mValue=9; - } - else { - if (chaine.charAt(pos+3)=='h') { - esp.mValue=4; + break; + case 'e': + if ((chaine.charAt(pos+1)=='x') && (chaine.charAt(pos+2)=='p')) { + esp.mValue=3; + oper.mValue=6; + } + else oper.mValue=-10; + break; + case 'l': + if (chaine.charAt(pos+1)=='n') { + esp.mValue=2; + oper.mValue=7; + } + else if ((chaine.charAt(pos+1)=='o') && (chaine.charAt(pos+2)=='g')){ + esp.mValue=3; + oper.mValue=8; + } + else oper.mValue=-10; + break; + case 's': + if (chaine.charAt(pos+1)=='h') { + esp.mValue=2; oper.mValue=17; } - else { - esp.mValue=3; - oper.mValue=11; - } - } - break; - case 't': - if (chaine.charAt(pos+1)=='h') { - esp.mValue=2; - oper.mValue=19; - } - else if ((chaine.charAt(pos+1)=='a') && (chaine.charAt(pos+2)=='n')) { - if (chaine.charAt(pos+3)=='h') { + else if (chaine.charAt(pos+1)=='q') { esp.mValue=4; + oper.mValue=9; + } + else { + if (chaine.charAt(pos+3)=='h') { + esp.mValue=4; + oper.mValue=17; + } + else { + esp.mValue=3; + oper.mValue=11; + } + } + break; + case 't': + if (chaine.charAt(pos+1)=='h') { + esp.mValue=2; oper.mValue=19; } - else { - esp.mValue=3; - oper.mValue=13; + else if ((chaine.charAt(pos+1)=='a') && (chaine.charAt(pos+2)=='n')) { + if (chaine.charAt(pos+3)=='h') { + esp.mValue=4; + oper.mValue=19; + } + else { + esp.mValue=3; + oper.mValue=13; + } } + else oper.mValue=-10; + break; + default: + oper.mValue=-10; + break; } - else oper.mValue=-10; - break; - default: - oper.mValue=-10; - break; - } } //.................................................................................... CopyPartialString