implemented IF() function

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@479289 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Amol S. Deshmukh 2006-11-26 06:13:29 +00:00
parent c2bd2b7b1c
commit 3cad882697
2 changed files with 40 additions and 1 deletions

View 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

View File

@ -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;
}
}