]> gerrit.simantics Code Review - simantics/sysdyn.git/commitdiff
refs #5224
authorvillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 26 Aug 2014 11:59:08 +0000 (11:59 +0000)
committervillberg <villberg@ac1ea38d-2e2b-0410-8846-a27921b304fc>
Tue, 26 Aug 2014 11:59:08 +0000 (11:59 +0000)
git-svn-id: https://www.simantics.org/svn/simantics/sysdyn/trunk@30141 ac1ea38d-2e2b-0410-8846-a27921b304fc

fi.semantum.sysdyn.solver/src/fi/semantum/sysdyn/solver/Negation.java

index 8cdad84e33600d9cc922fcd3cfde66aded68cb35..979594514bdc945c006f5d98cde70cc7e6c9035f 100644 (file)
@@ -12,6 +12,8 @@ package fi.semantum.sysdyn.solver;
 \r
 import java.util.Map;\r
 \r
+import fi.semantum.sysdyn.solver.Array.Modifier;\r
+\r
 public class Negation implements IExpression {\r
        \r
     public IExpression exp;\r
@@ -27,9 +29,26 @@ public class Negation implements IExpression {
     \r
        @Override\r
        public Object evaluate(IEnvironment environment) {\r
-               Double d = (Double)exp.evaluate(environment);\r
-               if(d == null) return null;\r
-               return -d;\r
+               Object value = exp.evaluate(environment);\r
+               if(value == null) return null;\r
+               if(value instanceof Double) {\r
+                       return -((Double)value); \r
+               } else if(value instanceof Array) {\r
+                       return ((Array)value).copy(new Modifier() {\r
+\r
+                               @Override\r
+                               public Object modify(Object o) {\r
+                                       if(o instanceof Double) {\r
+                                               return -((Double)o); \r
+                                       } else {\r
+                                               throw new IllegalStateException();\r
+                                       }\r
+                               }\r
+                               \r
+                       });\r
+               } else {\r
+                       throw new IllegalStateException();\r
+               }\r
        }\r
     \r
        @Override\r