From 2b0eb9be33b0496d9ef13144e3ca2b64a7212601 Mon Sep 17 00:00:00 2001 From: "Amol S. Deshmukh" Date: Sun, 26 Nov 2006 06:13:29 +0000 Subject: [PATCH] implemented IF() function git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@479289 13f79535-47bb-0310-9956-ffa450edef68 --- .../record/formula/eval/FunctionEval.java | 2 +- .../poi/hssf/record/formula/functions/If.java | 39 +++++++++++++++++++ 2 files changed, 40 insertions(+), 1 deletion(-) create mode 100644 src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/If.java diff --git a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FunctionEval.java b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FunctionEval.java index e6108c8687..3910509164 100644 --- a/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FunctionEval.java +++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/eval/FunctionEval.java @@ -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 index 0000000000..15dc990d50 --- /dev/null +++ b/src/scratchpad/src/org/apache/poi/hssf/record/formula/functions/If.java @@ -0,0 +1,39 @@ +/* + * Created on Nov 25, 2006 + * + */ +package org.apache.poi.hssf.record.formula.functions; + +import org.apache.poi.hssf.record.formula.eval.BoolEval; +import org.apache.poi.hssf.record.formula.eval.ErrorEval; +import org.apache.poi.hssf.record.formula.eval.Eval; + +/** + * @author Amol S. Deshmukh < amolweb at ya hoo dot com > + * + */ +public class If implements Function { + + public Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol) { + Eval retval = null; + Eval evalWhenFalse = BoolEval.FALSE; + switch (evals.length) { + case 3: + evalWhenFalse = evals[2]; + case 2: + BoolEval beval = (BoolEval) evals[0]; + if (beval.getBooleanValue()) { + retval = evals[1]; + } + else { + retval = evalWhenFalse; + } + break; + default: + retval = ErrorEval.UNKNOWN_ERROR; + } + return retval; + } + + +} -- 2.39.5