]> source.dussan.org Git - poi.git/commitdiff
implemented IF() function
authorAmol S. Deshmukh <amol@apache.org>
Sun, 26 Nov 2006 06:13:29 +0000 (06:13 +0000)
committerAmol S. Deshmukh <amol@apache.org>
Sun, 26 Nov 2006 06:13:29 +0000 (06:13 +0000)
git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@479289 13f79535-47bb-0310-9956-ffa450edef68

src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FunctionEval.java
src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/If.java [new file with mode: 0644]

index e6108c8687c79021d7e5463f4dd2fbd9eb56e9bb..3910509164e4fe7e4a94916af6dbb319af02d461 100644 (file)
@@ -23,7 +23,7 @@ public abstract class FunctionEval implements OperationEval {
     private static Function[] produceFunctions() {
         Function[] retval = new Function[368];
         retval[0] = new Count(); // COUNT
-        retval[1] = null; // Specialflag(); // SPECIALFLAG
+        retval[1] = new If(); // IF
         retval[2] = new IsNa(); // ISNA
         retval[3] = new IsError(); // ISERROR
         retval[4] = new Sum(); // SUM
diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/If.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/If.java
new file mode 100644 (file)
index 0000000..15dc990
--- /dev/null
@@ -0,0 +1,39 @@
+/*\r
+ * Created on Nov 25, 2006\r
+ *\r
+ */\r
+package org.apache.poi.hssf.record.formula.functions;\r
+\r
+import org.apache.poi.hssf.record.formula.eval.BoolEval;\r
+import org.apache.poi.hssf.record.formula.eval.ErrorEval;\r
+import org.apache.poi.hssf.record.formula.eval.Eval;\r
+\r
+/**\r
+ * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;\r
+ * \r
+ */\r
+public class If implements Function {\r
+\r
+    public Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol) {\r
+        Eval retval = null;\r
+        Eval evalWhenFalse = BoolEval.FALSE;\r
+        switch (evals.length) {\r
+        case 3:\r
+            evalWhenFalse = evals[2];\r
+        case 2:\r
+            BoolEval beval = (BoolEval) evals[0];\r
+            if (beval.getBooleanValue()) {\r
+                retval = evals[1];\r
+            }\r
+            else {\r
+                retval = evalWhenFalse;\r
+            }\r
+            break;\r
+        default:\r
+            retval = ErrorEval.UNKNOWN_ERROR;\r
+        }\r
+        return retval;\r
+    }\r
+\r
+\r
+}\r