You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2008/09/01 04:26:33 UTC

svn commit: r690836 - in /poi/trunk/src: java/org/apache/poi/hssf/record/formula/functions/If.java testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls

Author: josh
Date: Sun Aug 31 19:26:33 2008
New Revision: 690836

URL: http://svn.apache.org/viewvc?rev=690836&view=rev
Log:
Fixed IF() to handle different types for the first arg

Modified:
    poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/If.java
    poi/trunk/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/If.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/If.java?rev=690836&r1=690835&r2=690836&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/If.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/If.java Sun Aug 31 19:26:33 2008
@@ -30,29 +30,32 @@
  */
 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) {

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls?rev=690836&r1=690835&r2=690836&view=diff
==============================================================================
Binary files - no diff available.



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org