Fixed negative number bug in exp4j and custom expressions.
[debian/openrocket] / core / src / net / sf / openrocket / simulation / customexpression / CustomExpression.java
index 2ac41ffc0651bc7a094998089af45607d37c5c28..47a5dff1fcb98ed3eef8261910006e6d15e009cb 100644 (file)
@@ -175,7 +175,7 @@ public class CustomExpression implements Cloneable{
                        names.add(type.getName());
 
                if (doc != null){
-                       ArrayList<CustomExpression> expressions = doc.getCustomExpressions();
+                       List<CustomExpression> expressions = doc.getCustomExpressions();
                        for (CustomExpression exp : expressions ){
                                if (exp != this)
                                        names.add(exp.getName());
@@ -200,11 +200,11 @@ public class CustomExpression implements Cloneable{
        }
        
        public boolean checkSymbol(){
-               if (symbol.trim().isEmpty())
+               if ("".equals(symbol.trim()))
                        return false;
                
                // No bad characters
-               for (char c : "0123456789.,()[]{}<>:#@%^&* ".toCharArray())
+               for (char c : "0123456789.,()[]{}<>:#@%^&*$ ".toCharArray())
                        if (symbol.indexOf(c) != -1 )
                                return false;
                
@@ -226,11 +226,11 @@ public class CustomExpression implements Cloneable{
        }
        
        public boolean checkName(){
-               if (name.trim().isEmpty())
+               if ("".equals(name.trim()))
                        return false;
                
                // No characters that could mess things up saving etc
-               for (char c : ",()[]{}<>#".toCharArray())
+               for (char c : ",()[]{}<>#$".toCharArray())
                        if (name.indexOf(c) != -1 )
                                return false;
                
@@ -275,7 +275,7 @@ public class CustomExpression implements Cloneable{
         * building the expression.
         */
        public boolean checkExpression(){
-               if (expression.trim().isEmpty()){
+               if ("".equals(expression.trim())){
                        return false;
                }
                
@@ -293,6 +293,7 @@ public class CustomExpression implements Cloneable{
                                        }
                                        else break;
                                case '#' : return false;
+                               case '$' : return false;
                                case '=' : return false;
                        }
                }
@@ -412,7 +413,7 @@ public class CustomExpression implements Cloneable{
         */
        public void addToDocument(){
                // Abort if exact expression already in
-               ArrayList<CustomExpression> expressions = doc.getCustomExpressions();
+               List<CustomExpression> expressions = doc.getCustomExpressions();
                if ( !expressions.isEmpty() ) {
                        // check if expression already exists
                        if ( expressions.contains(this) ){
@@ -465,12 +466,12 @@ public class CustomExpression implements Cloneable{
        } 
        
        /*
-        * Returns a simple all upper case string hash code with a proceeding # mark.
+        * Returns a simple all upper case string hash code with a proceeding $ mark.
         * Used for temporary substitution when evaluating index and range expressions.
         */
        public String hash(){
                Integer hashint = new Integer(this.getExpressionString().hashCode());
-               String hash = "#";
+               String hash = "$";
                for (char c : hashint.toString().toCharArray()){
                        char newc = (char) (c + 17);
                        hash = hash + newc;