From: Josh Micich Date: Mon, 1 Sep 2008 02:26:33 +0000 (+0000) Subject: Fixed IF() to handle different types for the first arg X-Git-Tag: REL_3_2_FINAL~105 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=d93c9c520de8dda2f4cfcadb642aa5f7fc8e378d;p=poi.git Fixed IF() to handle different types for the first arg git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@690836 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/java/org/apache/poi/hssf/record/formula/functions/If.java b/src/java/org/apache/poi/hssf/record/formula/functions/If.java index 4b3e10a19f..4b066b8226 100644 --- a/src/java/org/apache/poi/hssf/record/formula/functions/If.java +++ b/src/java/org/apache/poi/hssf/record/formula/functions/If.java @@ -30,29 +30,32 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval; */ public final class If implements Function { - public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { - - Eval evalWhenFalse = BoolEval.FALSE; - switch (args.length) { - case 3: - evalWhenFalse = args[2]; - case 2: - boolean b; - try { - b = evaluateFirstArg(args[0], srcCellRow, srcCellCol); - } catch (EvaluationException e) { - return e.getErrorEval(); - } - if (b) { - return args[1]; - } - return evalWhenFalse; - default: - return ErrorEval.VALUE_INVALID; - } - } + public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { + Eval falseResult; + switch (args.length) { + case 3: + falseResult = args[2]; + break; + case 2: + falseResult = BoolEval.FALSE; + break; + default: + return ErrorEval.VALUE_INVALID; + } + boolean b; + try { + b = evaluateFirstArg(args[0], srcCellRow, srcCellCol); + } catch (EvaluationException e) { + return e.getErrorEval(); + } + if (b) { + return args[1]; + } + return falseResult; + } - private static boolean evaluateFirstArg(Eval arg, int srcCellRow, short srcCellCol) throws EvaluationException { + private static boolean evaluateFirstArg(Eval arg, int srcCellRow, short srcCellCol) + throws EvaluationException { ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol); Boolean b = OperandResolver.coerceValueToBoolean(ve, false); if (b == null) { diff --git a/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls b/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls index e1193179fe..51e370bfb9 100644 Binary files a/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls and b/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls differ