Replaced obsolete Eval with ValueEval in signature of Function.evaluate()

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@805119 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2009-08-17 20:04:45 +00:00
parent b25137db49
commit e72a30c440
63 changed files with 338 additions and 476 deletions

View File

@ -20,7 +20,6 @@ package org.apache.poi.hssf.record.formula.atp;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.functions.FreeRefFunction; import org.apache.poi.hssf.record.formula.functions.FreeRefFunction;
import org.apache.poi.ss.formula.EvaluationWorkbook; import org.apache.poi.ss.formula.EvaluationWorkbook;

View File

@ -20,7 +20,63 @@ package org.apache.poi.hssf.record.formula.eval;
import org.apache.poi.hssf.record.formula.AbstractFunctionPtg; import org.apache.poi.hssf.record.formula.AbstractFunctionPtg;
import org.apache.poi.hssf.record.formula.function.FunctionMetadata; import org.apache.poi.hssf.record.formula.function.FunctionMetadata;
import org.apache.poi.hssf.record.formula.function.FunctionMetadataRegistry; import org.apache.poi.hssf.record.formula.function.FunctionMetadataRegistry;
import org.apache.poi.hssf.record.formula.functions.*; import org.apache.poi.hssf.record.formula.functions.AggregateFunction;
import org.apache.poi.hssf.record.formula.functions.And;
import org.apache.poi.hssf.record.formula.functions.CalendarFieldFunction;
import org.apache.poi.hssf.record.formula.functions.Choose;
import org.apache.poi.hssf.record.formula.functions.Column;
import org.apache.poi.hssf.record.formula.functions.Columns;
import org.apache.poi.hssf.record.formula.functions.Count;
import org.apache.poi.hssf.record.formula.functions.Counta;
import org.apache.poi.hssf.record.formula.functions.Countif;
import org.apache.poi.hssf.record.formula.functions.DateFunc;
import org.apache.poi.hssf.record.formula.functions.Errortype;
import org.apache.poi.hssf.record.formula.functions.Even;
import org.apache.poi.hssf.record.formula.functions.False;
import org.apache.poi.hssf.record.formula.functions.FinanceFunction;
import org.apache.poi.hssf.record.formula.functions.Find;
import org.apache.poi.hssf.record.formula.functions.FreeRefFunction;
import org.apache.poi.hssf.record.formula.functions.Function;
import org.apache.poi.hssf.record.formula.functions.Hlookup;
import org.apache.poi.hssf.record.formula.functions.Hyperlink;
import org.apache.poi.hssf.record.formula.functions.If;
import org.apache.poi.hssf.record.formula.functions.Index;
import org.apache.poi.hssf.record.formula.functions.Indirect;
import org.apache.poi.hssf.record.formula.functions.IsError;
import org.apache.poi.hssf.record.formula.functions.IsNa;
import org.apache.poi.hssf.record.formula.functions.Isblank;
import org.apache.poi.hssf.record.formula.functions.Isref;
import org.apache.poi.hssf.record.formula.functions.LogicalFunction;
import org.apache.poi.hssf.record.formula.functions.Lookup;
import org.apache.poi.hssf.record.formula.functions.Match;
import org.apache.poi.hssf.record.formula.functions.MinaMaxa;
import org.apache.poi.hssf.record.formula.functions.Mode;
import org.apache.poi.hssf.record.formula.functions.Na;
import org.apache.poi.hssf.record.formula.functions.Not;
import org.apache.poi.hssf.record.formula.functions.NotImplementedFunction;
import org.apache.poi.hssf.record.formula.functions.Now;
import org.apache.poi.hssf.record.formula.functions.NumericFunction;
import org.apache.poi.hssf.record.formula.functions.Odd;
import org.apache.poi.hssf.record.formula.functions.Offset;
import org.apache.poi.hssf.record.formula.functions.Or;
import org.apache.poi.hssf.record.formula.functions.Pi;
import org.apache.poi.hssf.record.formula.functions.Rand;
import org.apache.poi.hssf.record.formula.functions.Replace;
import org.apache.poi.hssf.record.formula.functions.Row;
import org.apache.poi.hssf.record.formula.functions.Rows;
import org.apache.poi.hssf.record.formula.functions.Substitute;
import org.apache.poi.hssf.record.formula.functions.Sumif;
import org.apache.poi.hssf.record.formula.functions.Sumproduct;
import org.apache.poi.hssf.record.formula.functions.Sumx2my2;
import org.apache.poi.hssf.record.formula.functions.Sumx2py2;
import org.apache.poi.hssf.record.formula.functions.Sumxmy2;
import org.apache.poi.hssf.record.formula.functions.T;
import org.apache.poi.hssf.record.formula.functions.TextFunction;
import org.apache.poi.hssf.record.formula.functions.Time;
import org.apache.poi.hssf.record.formula.functions.Today;
import org.apache.poi.hssf.record.formula.functions.True;
import org.apache.poi.hssf.record.formula.functions.Value;
import org.apache.poi.hssf.record.formula.functions.Vlookup;
import org.apache.poi.ss.formula.eval.NotImplementedException; import org.apache.poi.ss.formula.eval.NotImplementedException;
/** /**
@ -151,8 +207,8 @@ public final class FunctionEval implements OperationEval {
retval[124] = new Find(); retval[124] = new Find();
retval[127] = new Istext(); retval[127] = LogicalFunction.IsText;
retval[128] = new Isnumber(); retval[128] = LogicalFunction.IsNumber;
retval[129] = new Isblank(); retval[129] = new Isblank();
retval[130] = new T(); retval[130] = new T();
@ -163,9 +219,9 @@ public final class FunctionEval implements OperationEval {
retval[183] = AggregateFunction.PRODUCT; retval[183] = AggregateFunction.PRODUCT;
retval[184] = NumericFunction.FACT; retval[184] = NumericFunction.FACT;
retval[190] = new Isnontext(); retval[190] = LogicalFunction.IsNonText;
retval[198] = new Islogical(); retval[198] = LogicalFunction.IsLogical;
retval[212] = NumericFunction.ROUNDUP; retval[212] = NumericFunction.ROUNDUP;
retval[213] = NumericFunction.ROUNDDOWN; retval[213] = NumericFunction.ROUNDDOWN;
@ -248,7 +304,7 @@ public final class FunctionEval implements OperationEval {
if (f == null) { if (f == null) {
throw new NotImplementedException("FuncIx=" + getFunctionIndex()); throw new NotImplementedException("FuncIx=" + getFunctionIndex());
} }
return (ValueEval) f.evaluate(operands, srcRow, srcCol); return f.evaluate(operands, srcRow, srcCol);
} }
public int getNumberOfOperands() { public int getNumberOfOperands() {

View File

@ -39,7 +39,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval;
*/ */
public abstract class BooleanFunction implements Function { public abstract class BooleanFunction implements Function {
public final Eval evaluate(Eval[] args, int srcRow, short srcCol) { public final ValueEval evaluate(ValueEval[] args, int srcRow, short srcCol) {
if (args.length < 1) { if (args.length < 1) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
} }

View File

@ -22,7 +22,6 @@ import java.util.Date;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException; import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.OperandResolver;
@ -49,7 +48,7 @@ public final class CalendarFieldFunction implements Function {
_needsOneBaseAdjustment = needsOneBaseAdjustment; _needsOneBaseAdjustment = needsOneBaseAdjustment;
} }
public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] operands, int srcCellRow, short srcCellCol) {
if (operands.length != 1) { if (operands.length != 1) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
} }

View File

@ -18,7 +18,6 @@
package org.apache.poi.hssf.record.formula.functions; package org.apache.poi.hssf.record.formula.functions;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException; import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
@ -29,7 +28,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval;
*/ */
public final class Choose implements Function { public final class Choose implements Function {
public Eval evaluate(Eval[] args, int srcRowIndex, short srcColumnIndex) { public ValueEval evaluate(ValueEval[] args, int srcRowIndex, short srcColumnIndex) {
if (args.length < 2) { if (args.length < 2) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
} }

View File

@ -19,13 +19,12 @@ package org.apache.poi.hssf.record.formula.functions;
import org.apache.poi.hssf.record.formula.eval.AreaEval; import org.apache.poi.hssf.record.formula.eval.AreaEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.RefEval; import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
public final class Column implements Function { public final class Column implements Function {
public Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] evals, int srcCellRow, short srcCellCol) {
ValueEval retval = null; ValueEval retval = null;
int cnum = -1; int cnum = -1;

View File

@ -22,6 +22,7 @@ import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.RefEval; import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
/** /**
* Implementation for Excel COLUMNS function. * Implementation for Excel COLUMNS function.
@ -30,7 +31,7 @@ import org.apache.poi.hssf.record.formula.eval.RefEval;
*/ */
public final class Columns implements Function { public final class Columns implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
switch(args.length) { switch(args.length) {
case 1: case 1:
// expected // expected

View File

@ -21,6 +21,7 @@ import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.MissingArgEval; import org.apache.poi.hssf.record.formula.eval.MissingArgEval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.functions.CountUtils.I_MatchPredicate; import org.apache.poi.hssf.record.formula.functions.CountUtils.I_MatchPredicate;
/** /**
@ -36,7 +37,7 @@ import org.apache.poi.hssf.record.formula.functions.CountUtils.I_MatchPredicate;
*/ */
public final class Count implements Function { public final class Count implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
int nArgs = args.length; int nArgs = args.length;
if (nArgs < 1) { if (nArgs < 1) {
// too few arguments // too few arguments

View File

@ -21,6 +21,7 @@ import org.apache.poi.hssf.record.formula.eval.BlankEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.functions.CountUtils.I_MatchPredicate; import org.apache.poi.hssf.record.formula.functions.CountUtils.I_MatchPredicate;
/** /**
@ -34,7 +35,7 @@ import org.apache.poi.hssf.record.formula.functions.CountUtils.I_MatchPredicate;
*/ */
public final class Counta implements Function { public final class Counta implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
int nArgs = args.length; int nArgs = args.length;
if (nArgs < 1) { if (nArgs < 1) {
// too few arguments // too few arguments

View File

@ -29,6 +29,7 @@ import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.RefEval; import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.StringEval; import org.apache.poi.hssf.record.formula.eval.StringEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.functions.CountUtils.I_MatchPredicate; import org.apache.poi.hssf.record.formula.functions.CountUtils.I_MatchPredicate;
import org.apache.poi.ss.usermodel.ErrorConstants; import org.apache.poi.ss.usermodel.ErrorConstants;
@ -400,7 +401,7 @@ public final class Countif implements Function {
} }
} }
public Eval evaluate(Eval[] args, int srcRowIndex, short srcColumnIndex) { public ValueEval evaluate(ValueEval[] args, int srcRowIndex, short srcColumnIndex) {
switch(args.length) { switch(args.length) {
case 2: case 2:
// expected // expected

View File

@ -18,10 +18,10 @@
package org.apache.poi.hssf.record.formula.functions; package org.apache.poi.hssf.record.formula.functions;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException; import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants; import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
/** /**
@ -52,7 +52,7 @@ import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
*/ */
public final class Errortype implements Function { public final class Errortype implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
try { try {
OperandResolver.getSingleValue(args[0], srcCellRow, srcCellCol); OperandResolver.getSingleValue(args[0], srcCellRow, srcCellCol);

View File

@ -19,7 +19,6 @@ 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.BoolEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
/** /**
@ -28,7 +27,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval;
*/ */
public final class False implements Function { public final class False implements Function {
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) { public ValueEval evaluate(ValueEval[] operands, int srcRow, short srcCol) {
ValueEval retval; ValueEval retval;
switch (operands.length) { switch (operands.length) {
default: default:

View File

@ -19,7 +19,6 @@ package org.apache.poi.hssf.record.formula.functions;
import org.apache.poi.hssf.record.formula.eval.BlankEval; import org.apache.poi.hssf.record.formula.eval.BlankEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.MissingArgEval; import org.apache.poi.hssf.record.formula.eval.MissingArgEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
@ -31,16 +30,14 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval;
public interface Function { public interface Function {
/** /**
* @param args the evaluated function arguments. Elements of this array typically implement * @param args the evaluated function arguments. Empty values are represented with
* {@link ValueEval}. Empty values are represented with {@link BlankEval} or {@link * {@link BlankEval} or {@link MissingArgEval}, never <code>null</code>.
* MissingArgEval}, never <code>null</code>.
* @param srcRowIndex row index of the cell containing the formula under evaluation * @param srcRowIndex row index of the cell containing the formula under evaluation
* @param srcColumnIndex column index of the cell containing the formula under evaluation * @param srcColumnIndex column index of the cell containing the formula under evaluation
* @return The evaluated result, possibly an {@link ErrorEval}, never <code>null</code>. * @return The evaluated result, possibly an {@link ErrorEval}, never <code>null</code>.
* <b>Note</b> - Excel uses the error code <i>#NUM!</i> instead of IEEE <i>NaN</i>, so when * <b>Note</b> - Excel uses the error code <i>#NUM!</i> instead of IEEE <i>NaN</i>, so when
* numeric functions evaluate to {@link Double#NaN} be sure to translate the result to {@link * numeric functions evaluate to {@link Double#NaN} be sure to translate the result to {@link
* ErrorEval#NUM_ERROR}. * ErrorEval#NUM_ERROR}.
*
*/ */
Eval evaluate(Eval[] args, int srcRowIndex, short srcColumnIndex); ValueEval evaluate(ValueEval[] args, int srcRowIndex, short srcColumnIndex);
} }

View File

@ -42,7 +42,7 @@ import org.apache.poi.hssf.record.formula.functions.LookupUtils.ValueVector;
*/ */
public final class Hlookup implements Function { public final class Hlookup implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
Eval arg3 = null; Eval arg3 = null;
switch(args.length) { switch(args.length) {
case 4: case 4:

View File

@ -18,10 +18,10 @@
package org.apache.poi.hssf.record.formula.functions; package org.apache.poi.hssf.record.formula.functions;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException; import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.StringEval; import org.apache.poi.hssf.record.formula.eval.StringEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
/** /**
* Implementation of Excel HYPERLINK function.<p/> * Implementation of Excel HYPERLINK function.<p/>
@ -41,7 +41,7 @@ import org.apache.poi.hssf.record.formula.eval.StringEval;
*/ */
public final class Hyperlink implements Function { public final class Hyperlink implements Function {
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) { public ValueEval evaluate(ValueEval[] operands, int srcRow, short srcCol) {
int lastArgIx = operands.length - 1; int lastArgIx = operands.length - 1;
if (lastArgIx < 0 || lastArgIx > 1) { if (lastArgIx < 0 || lastArgIx > 1) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;

View File

@ -19,7 +19,6 @@ 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.BoolEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException; import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
@ -30,8 +29,8 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval;
*/ */
public final class If implements Function { public final class If implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
Eval falseResult; ValueEval falseResult;
switch (args.length) { switch (args.length) {
case 3: case 3:
falseResult = args[2]; falseResult = args[2];
@ -54,7 +53,7 @@ public final class If implements Function {
return falseResult; return falseResult;
} }
private static boolean evaluateFirstArg(Eval arg, int srcCellRow, short srcCellCol) private static boolean evaluateFirstArg(ValueEval arg, int srcCellRow, short srcCellCol)
throws EvaluationException { throws EvaluationException {
ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol); ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
Boolean b = OperandResolver.coerceValueToBoolean(ve, false); Boolean b = OperandResolver.coerceValueToBoolean(ve, false);

View File

@ -47,7 +47,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval;
*/ */
public final class Index implements Function { public final class Index implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
int nArgs = args.length; int nArgs = args.length;
if(nArgs < 2) { if(nArgs < 2) {
// too few arguments // too few arguments

View File

@ -20,7 +20,6 @@ package org.apache.poi.hssf.record.formula.functions;
import org.apache.poi.hssf.record.formula.eval.AreaEval; import org.apache.poi.hssf.record.formula.eval.AreaEval;
import org.apache.poi.hssf.record.formula.eval.BoolEval; 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.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.RefEval; import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
@ -30,7 +29,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval;
*/ */
public final class IsError implements Function { public final class IsError implements Function {
public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] operands, int srcCellRow, short srcCellCol) {
ValueEval retval = null; ValueEval retval = null;
boolean b = false; boolean b = false;

View File

@ -22,6 +22,7 @@ import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException; import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.ss.usermodel.ErrorConstants; import org.apache.poi.ss.usermodel.ErrorConstants;
/** /**
@ -38,7 +39,7 @@ import org.apache.poi.ss.usermodel.ErrorConstants;
*/ */
public final class IsNa implements Function { public final class IsNa implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
if(args.length != 1) { if(args.length != 1) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
} }

View File

@ -31,7 +31,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval;
*/ */
public final class Isblank implements Function { public final class Isblank implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
if(args.length != 1) { if(args.length != 1) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
} }

View File

@ -1,53 +0,0 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
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;
import org.apache.poi.hssf.record.formula.eval.RefEval;
/**
* @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
*
*/
public final class Islogical extends LogicalFunction {
public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
Eval retval = BoolEval.FALSE;
switch (operands.length) {
default:
retval = ErrorEval.VALUE_INVALID;
break;
case 1:
Eval eval = operands[0];
if (eval instanceof BoolEval) {
retval = BoolEval.TRUE;
}
else if (eval instanceof RefEval) {
Eval xlatedEval = xlateRefEval((RefEval) eval);
if (xlatedEval instanceof BoolEval) {
retval = BoolEval.TRUE;
}
}
}
return retval;
}
}

View File

@ -1,53 +0,0 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
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;
import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.StringEval;
/**
* @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
*
*/
public final class Isnontext extends LogicalFunction {
public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
Eval retval = BoolEval.TRUE;
switch (operands.length) {
default:
retval = ErrorEval.VALUE_INVALID;
break;
case 1:
Eval eval = operands[0];
if (eval instanceof StringEval) {
retval = BoolEval.FALSE;
}
else if (eval instanceof RefEval) {
Eval xlatedEval = xlateRefEval((RefEval) eval);
if (xlatedEval instanceof StringEval) {
retval = BoolEval.FALSE;
}
}
}
return retval;
}
}

View File

@ -1,53 +0,0 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
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;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.RefEval;
/**
* @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
*
*/
public final class Isnumber extends LogicalFunction {
public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
Eval retval = BoolEval.FALSE;
switch (operands.length) {
default:
retval = ErrorEval.VALUE_INVALID;
break;
case 1:
Eval eval = operands[0];
if (eval instanceof NumberEval) {
retval = BoolEval.TRUE;
}
else if (eval instanceof RefEval) {
Eval xlatedEval = xlateRefEval((RefEval) eval);
if (xlatedEval instanceof NumberEval) {
retval = BoolEval.TRUE;
}
}
}
return retval;
}
}

View File

@ -22,26 +22,22 @@ 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.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.RefEval; import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
/** /**
* @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt; * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
*
*/ */
public final class Isref implements Function { public final class Isref implements Function {
public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] operands, int srcCellRow, short srcCellCol) {
Eval retval = BoolEval.FALSE; if (operands.length != 1) {
return ErrorEval.VALUE_INVALID;
}
switch (operands.length) {
default:
retval = ErrorEval.VALUE_INVALID;
break;
case 1:
Eval eval = operands[0]; Eval eval = operands[0];
if (eval instanceof RefEval || eval instanceof AreaEval) { if (eval instanceof RefEval || eval instanceof AreaEval) {
retval = BoolEval.TRUE; return BoolEval.TRUE;
}
} }
return retval; return BoolEval.FALSE;
} }
} }

View File

@ -1,53 +0,0 @@
/* ====================================================================
Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You under the Apache License, Version 2.0
(the "License"); you may not use this file except in compliance with
the License. You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.
==================================================================== */
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;
import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.StringEval;
/**
* @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
*
*/
public final class Istext extends LogicalFunction {
public Eval evaluate(Eval[] operands, int srcCellRow, short srcCellCol) {
Eval retval = BoolEval.FALSE;
switch (operands.length) {
default:
retval = ErrorEval.VALUE_INVALID;
break;
case 1:
Eval eval = operands[0];
if (eval instanceof StringEval) {
retval = BoolEval.TRUE;
}
else if (eval instanceof RefEval) {
Eval xlatedEval = xlateRefEval((RefEval) eval);
if (xlatedEval instanceof StringEval) {
retval = BoolEval.TRUE;
}
}
}
return retval;
}
}

View File

@ -17,21 +17,24 @@
package org.apache.poi.hssf.record.formula.functions; 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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.RefEval; import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.StringEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
/** /**
* @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt; * @author Amol S. Deshmukh &lt; amolweb at ya hoo dot com &gt;
*
*/ */
public abstract class LogicalFunction implements Function { public abstract class LogicalFunction implements Function {
/** /**
* recursively evaluate any RefEvals * recursively evaluate any RefEvals TODO - use {@link OperandResolver}
* TODO - use {@link OperandResolver}
*/ */
protected ValueEval xlateRefEval(RefEval reval) { private static ValueEval xlateRefEval(RefEval reval) {
ValueEval retval = reval.getInnerValueEval(); ValueEval retval = reval.getInnerValueEval();
if (retval instanceof RefEval) { if (retval instanceof RefEval) {
@ -41,4 +44,49 @@ public abstract class LogicalFunction implements Function {
return retval; return retval;
} }
public final ValueEval evaluate(ValueEval[] operands, int srcCellRow, short srcCellCol) {
if (operands.length != 1) {
return ErrorEval.VALUE_INVALID;
}
ValueEval ve;
try {
ve = OperandResolver.getSingleValue(operands[0], srcCellRow, srcCellCol);
} catch (EvaluationException e) {
if (false) {
// Note - it is more usual to propagate error codes straight to the result like this:
return e.getErrorEval();
// but logical functions behave a little differently
}
// this will usually cause a 'FALSE' result except for ISNONTEXT()
ve = e.getErrorEval();
}
if (ve instanceof RefEval) {
ve = xlateRefEval((RefEval) ve);
}
return BoolEval.valueOf(evaluate(ve));
}
protected abstract boolean evaluate(ValueEval arg);
public static final Function IsLogical = new LogicalFunction() {
protected boolean evaluate(ValueEval arg) {
return arg instanceof BoolEval;
}
};
public static final Function IsNonText = new LogicalFunction() {
protected boolean evaluate(ValueEval arg) {
return !(arg instanceof StringEval);
}
};
public static final Function IsNumber = new LogicalFunction() {
protected boolean evaluate(ValueEval arg) {
return arg instanceof NumberEval;
}
};
public static final Function IsText = new LogicalFunction() {
protected boolean evaluate(ValueEval arg) {
return arg instanceof StringEval;
}
};
} }

View File

@ -19,7 +19,6 @@ package org.apache.poi.hssf.record.formula.functions;
import org.apache.poi.hssf.record.formula.eval.AreaEval; import org.apache.poi.hssf.record.formula.eval.AreaEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException; import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
@ -41,7 +40,7 @@ import org.apache.poi.hssf.record.formula.functions.LookupUtils.ValueVector;
*/ */
public final class Lookup implements Function { public final class Lookup implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
switch(args.length) { switch(args.length) {
case 3: case 3:
break; break;

View File

@ -67,7 +67,7 @@ import org.apache.poi.hssf.record.formula.functions.LookupUtils.ValueVector;
public final class Match implements Function { public final class Match implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
double match_type = 1; // default double match_type = 1; // default

View File

@ -74,7 +74,7 @@ public final class Mode implements Function {
} }
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
double result; double result;
try { try {
List<Double> temp = new ArrayList<Double>(); List<Double> temp = new ArrayList<Double>();

View File

@ -83,7 +83,7 @@ public abstract class MultiOperandNumericFunction implements Function {
private static final int DEFAULT_MAX_NUM_OPERANDS = 30; private static final int DEFAULT_MAX_NUM_OPERANDS = 30;
public final Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public final ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
double d; double d;
try { try {

View File

@ -18,7 +18,7 @@
package org.apache.poi.hssf.record.formula.functions; package org.apache.poi.hssf.record.formula.functions;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
/** /**
* Implementation of Excel function NA() * Implementation of Excel function NA()
@ -27,7 +27,7 @@ import org.apache.poi.hssf.record.formula.eval.Eval;
*/ */
public final class Na implements Function { public final class Na implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
return ErrorEval.NA; return ErrorEval.NA;
} }

View File

@ -19,7 +19,6 @@ 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.BoolEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException; import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
@ -33,7 +32,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval;
*/ */
public final class Not implements Function { public final class Not implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
if (args.length != 1) { if (args.length != 1) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
} }

View File

@ -17,7 +17,7 @@
package org.apache.poi.hssf.record.formula.functions; package org.apache.poi.hssf.record.formula.functions;
import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.ss.formula.eval.NotImplementedException; import org.apache.poi.ss.formula.eval.NotImplementedException;
/** /**
@ -38,7 +38,7 @@ public final class NotImplementedFunction implements Function {
_functionName = name; _functionName = name;
} }
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) { public ValueEval evaluate(ValueEval[] operands, int srcRow, short srcCol) {
throw new NotImplementedException(_functionName); throw new NotImplementedException(_functionName);
} }
public String getFunctionName() { public String getFunctionName() {

View File

@ -20,8 +20,8 @@ package org.apache.poi.hssf.record.formula.functions;
import java.util.Date; import java.util.Date;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.hssf.usermodel.HSSFDateUtil;
/** /**
@ -31,7 +31,7 @@ import org.apache.poi.hssf.usermodel.HSSFDateUtil;
*/ */
public final class Now implements Function { public final class Now implements Function {
public Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] evals, int srcCellRow, short srcCellCol) {
if (evals.length > 0) { if (evals.length > 0) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
} }

View File

@ -46,7 +46,7 @@ public abstract class NumericFunction implements Function {
} }
} }
public final Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public final ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
double result; double result;
try { try {
result = eval(args, srcCellRow, srcCellCol); result = eval(args, srcCellRow, srcCellCol);

View File

@ -164,7 +164,7 @@ public final class Offset implements Function {
} }
} }
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
if(args.length < 3 || args.length > 5) { if(args.length < 3 || args.length > 5) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
} }

View File

@ -18,7 +18,6 @@
package org.apache.poi.hssf.record.formula.functions; package org.apache.poi.hssf.record.formula.functions;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
@ -30,7 +29,7 @@ public final class Pi implements Function {
private static final NumberEval PI_EVAL = new NumberEval(Math.PI); private static final NumberEval PI_EVAL = new NumberEval(Math.PI);
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) { public ValueEval evaluate(ValueEval[] operands, int srcRow, short srcCol) {
ValueEval retval; ValueEval retval;
switch (operands.length) { switch (operands.length) {
default: default:

View File

@ -18,7 +18,6 @@
package org.apache.poi.hssf.record.formula.functions; package org.apache.poi.hssf.record.formula.functions;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
@ -28,7 +27,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval;
*/ */
public final class Rand implements Function { public final class Rand implements Function {
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) { public ValueEval evaluate(ValueEval[] operands, int srcRow, short srcCol) {
ValueEval retval; ValueEval retval;
switch (operands.length) { switch (operands.length) {
default: default:

View File

@ -19,14 +19,13 @@ package org.apache.poi.hssf.record.formula.functions;
import org.apache.poi.hssf.record.formula.eval.AreaEval; import org.apache.poi.hssf.record.formula.eval.AreaEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.RefEval; import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
public final class Row implements Function { public final class Row implements Function {
public Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] evals, int srcCellRow, short srcCellCol) {
ValueEval retval = null; ValueEval retval = null;
int rnum = -1; int rnum = -1;

View File

@ -22,6 +22,7 @@ import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.RefEval; import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
/** /**
* Implementation for Excel ROWS function. * Implementation for Excel ROWS function.
@ -30,7 +31,7 @@ import org.apache.poi.hssf.record.formula.eval.RefEval;
*/ */
public final class Rows implements Function { public final class Rows implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
switch(args.length) { switch(args.length) {
case 1: case 1:
// expected // expected

View File

@ -41,7 +41,7 @@ import org.apache.poi.hssf.record.formula.functions.CountUtils.I_MatchPredicate;
*/ */
public final class Sumif implements Function { public final class Sumif implements Function {
public Eval evaluate(Eval[] args, int srcRowIndex, short srcColumnIndex) { public ValueEval evaluate(ValueEval[] args, int srcRowIndex, short srcColumnIndex) {
if (args.length < 2) { if (args.length < 2) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
} }

View File

@ -20,7 +20,6 @@ package org.apache.poi.hssf.record.formula.functions;
import org.apache.poi.hssf.record.formula.eval.AreaEval; import org.apache.poi.hssf.record.formula.eval.AreaEval;
import org.apache.poi.hssf.record.formula.eval.BlankEval; import org.apache.poi.hssf.record.formula.eval.BlankEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException; import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval; import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
@ -54,14 +53,14 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval;
public final class Sumproduct implements Function { public final class Sumproduct implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
int maxN = args.length; int maxN = args.length;
if(maxN < 1) { if(maxN < 1) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
} }
Eval firstArg = args[0]; ValueEval firstArg = args[0];
try { try {
if(firstArg instanceof NumericValueEval) { if(firstArg instanceof NumericValueEval) {
return evaluateSingleProduct(args); return evaluateSingleProduct(args);
@ -83,7 +82,7 @@ public final class Sumproduct implements Function {
+ firstArg.getClass().getName() + ")"); + firstArg.getClass().getName() + ")");
} }
private static Eval evaluateSingleProduct(Eval[] evalArgs) throws EvaluationException { private static ValueEval evaluateSingleProduct(ValueEval[] evalArgs) throws EvaluationException {
int maxN = evalArgs.length; int maxN = evalArgs.length;
double term = 1D; double term = 1D;
@ -94,9 +93,9 @@ public final class Sumproduct implements Function {
return new NumberEval(term); return new NumberEval(term);
} }
private static double getScalarValue(Eval arg) throws EvaluationException { private static double getScalarValue(ValueEval arg) throws EvaluationException {
Eval eval; ValueEval eval;
if (arg instanceof RefEval) { if (arg instanceof RefEval) {
RefEval re = (RefEval) arg; RefEval re = (RefEval) arg;
eval = re.getInnerValueEval(); eval = re.getInnerValueEval();
@ -116,15 +115,10 @@ public final class Sumproduct implements Function {
eval = ae.getRelativeValue(0, 0); eval = ae.getRelativeValue(0, 0);
} }
if (!(eval instanceof ValueEval)) { return getProductTerm(eval, true);
throw new RuntimeException("Unexpected value eval class ("
+ eval.getClass().getName() + ")");
} }
return getProductTerm((ValueEval) eval, true); private static ValueEval evaluateAreaSumProduct(ValueEval[] evalArgs) throws EvaluationException {
}
private static Eval evaluateAreaSumProduct(Eval[] evalArgs) throws EvaluationException {
int maxN = evalArgs.length; int maxN = evalArgs.length;
AreaEval[] args = new AreaEval[maxN]; AreaEval[] args = new AreaEval[maxN];
try { try {

View File

@ -18,20 +18,20 @@
package org.apache.poi.hssf.record.formula.functions; package org.apache.poi.hssf.record.formula.functions;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.RefEval; import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.StringEval; import org.apache.poi.hssf.record.formula.eval.StringEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
public final class T implements Function { public final class T implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
switch (args.length) { switch (args.length) {
default: default:
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
case 1: case 1:
break; break;
} }
Eval arg = args[0]; ValueEval arg = args[0];
if (arg instanceof RefEval) { if (arg instanceof RefEval) {
RefEval re = (RefEval) arg; RefEval re = (RefEval) arg;
arg = re.getInnerValueEval(); arg = re.getInnerValueEval();

View File

@ -43,7 +43,7 @@ public abstract class TextFunction implements Function {
return OperandResolver.coerceValueToInt(ve); return OperandResolver.coerceValueToInt(ve);
} }
public final Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public final ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
try { try {
return evaluateFunc(args, srcCellRow, srcCellCol); return evaluateFunc(args, srcCellRow, srcCellCol);
} catch (EvaluationException e) { } catch (EvaluationException e) {

View File

@ -38,7 +38,7 @@ public final class Time implements Function {
private static final int SECONDS_PER_DAY = HOURS_PER_DAY * SECONDS_PER_HOUR; private static final int SECONDS_PER_DAY = HOURS_PER_DAY * SECONDS_PER_HOUR;
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
if (args.length != 3) { if (args.length != 3) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
} }

View File

@ -21,8 +21,8 @@ import java.util.Calendar;
import java.util.GregorianCalendar; import java.util.GregorianCalendar;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.usermodel.HSSFDateUtil; import org.apache.poi.hssf.usermodel.HSSFDateUtil;
/** /**
@ -32,7 +32,7 @@ import org.apache.poi.hssf.usermodel.HSSFDateUtil;
*/ */
public final class Today implements Function { public final class Today implements Function {
public Eval evaluate(Eval[] evals, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] evals, int srcCellRow, short srcCellCol) {
if (evals.length > 0) { if (evals.length > 0) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
} }

View File

@ -19,7 +19,6 @@ 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.BoolEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
/** /**
@ -28,7 +27,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval;
*/ */
public final class True implements Function { public final class True implements Function {
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) { public ValueEval evaluate(ValueEval[] operands, int srcRow, short srcCol) {
ValueEval retval; ValueEval retval;
switch (operands.length) { switch (operands.length) {
default: default:

View File

@ -18,7 +18,6 @@
package org.apache.poi.hssf.record.formula.functions; package org.apache.poi.hssf.record.formula.functions;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException; import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.OperandResolver; import org.apache.poi.hssf.record.formula.eval.OperandResolver;
@ -42,7 +41,7 @@ public final class Value implements Function {
private static final int MIN_DISTANCE_BETWEEN_THOUSANDS_SEPARATOR = 4; private static final int MIN_DISTANCE_BETWEEN_THOUSANDS_SEPARATOR = 4;
private static final Double ZERO = new Double(0.0); private static final Double ZERO = new Double(0.0);
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
if (args.length != 1) { if (args.length != 1) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
} }

View File

@ -42,7 +42,7 @@ import org.apache.poi.hssf.record.formula.functions.LookupUtils.ValueVector;
*/ */
public final class Vlookup implements Function { public final class Vlookup implements Function {
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
Eval arg3 = null; Eval arg3 = null;
switch(args.length) { switch(args.length) {
case 4: case 4:

View File

@ -97,7 +97,7 @@ public abstract class XYNumericFunction implements Function {
*/ */
protected abstract Accumulator createAccumulator(); protected abstract Accumulator createAccumulator();
public final Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) { public final ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
if (args.length != 2) { if (args.length != 2) {
return ErrorEval.VALUE_INVALID; return ErrorEval.VALUE_INVALID;
} }

View File

@ -22,7 +22,6 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.record.formula.eval.BlankEval; import org.apache.poi.hssf.record.formula.eval.BlankEval;
import org.apache.poi.hssf.record.formula.eval.BoolEval; 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.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
/** /**
@ -32,18 +31,18 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval;
*/ */
public final class TestAverage extends TestCase { public final class TestAverage extends TestCase {
private static Eval invokeAverage(Eval[] args) { private static ValueEval invokeAverage(ValueEval[] args) {
return AggregateFunction.AVERAGE.evaluate(args, -1, (short)-1); return AggregateFunction.AVERAGE.evaluate(args, -1, (short)-1);
} }
private void confirmAverage(Eval[] args, double expected) { private void confirmAverage(ValueEval[] args, double expected) {
Eval result = invokeAverage(args); ValueEval result = invokeAverage(args);
assertEquals(NumberEval.class, result.getClass()); assertEquals(NumberEval.class, result.getClass());
assertEquals(expected, ((NumberEval)result).getNumberValue(), 0); assertEquals(expected, ((NumberEval)result).getNumberValue(), 0);
} }
private void confirmAverage(Eval[] args, ErrorEval expectedError) { private void confirmAverage(ValueEval[] args, ErrorEval expectedError) {
Eval result = invokeAverage(args); ValueEval result = invokeAverage(args);
assertEquals(ErrorEval.class, result.getClass()); assertEquals(ErrorEval.class, result.getClass());
assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode()); assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
} }

View File

@ -101,7 +101,7 @@ public final class TestIndex extends TestCase {
ValueEval[] args = new ValueEval[] { arg0, MissingArgEval.instance, new NumberEval(2), }; ValueEval[] args = new ValueEval[] { arg0, MissingArgEval.instance, new NumberEval(2), };
ValueEval actualResult; ValueEval actualResult;
try { try {
actualResult = (ValueEval) FUNC_INST.evaluate(args, 1, (short)1); actualResult = FUNC_INST.evaluate(args, 1, (short)1);
} catch (RuntimeException e) { } catch (RuntimeException e) {
if (e.getMessage().equals("Unexpected arg eval type (org.apache.poi.hssf.record.formula.eval.MissingArgEval")) { if (e.getMessage().equals("Unexpected arg eval type (org.apache.poi.hssf.record.formula.eval.MissingArgEval")) {
throw new AssertionFailedError("Identified bug 47048b - INDEX() should support missing-arg"); throw new AssertionFailedError("Identified bug 47048b - INDEX() should support missing-arg");

View File

@ -22,9 +22,9 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.record.formula.eval.BlankEval; import org.apache.poi.hssf.record.formula.eval.BlankEval;
import org.apache.poi.hssf.record.formula.eval.BoolEval; 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.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.StringEval; import org.apache.poi.hssf.record.formula.eval.StringEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
/** /**
* Tests for Excel function LEN() * Tests for Excel function LEN()
* *
@ -32,20 +32,19 @@ import org.apache.poi.hssf.record.formula.eval.StringEval;
*/ */
public final class TestLen extends TestCase { public final class TestLen extends TestCase {
private static ValueEval invokeLen(ValueEval text) {
private static Eval invokeLen(Eval text) { ValueEval[] args = new ValueEval[] { text, };
Eval[] args = new Eval[] { text, };
return TextFunction.LEN.evaluate(args, -1, (short)-1); return TextFunction.LEN.evaluate(args, -1, (short)-1);
} }
private void confirmLen(Eval text, int expected) { private void confirmLen(ValueEval text, int expected) {
Eval result = invokeLen(text); ValueEval result = invokeLen(text);
assertEquals(NumberEval.class, result.getClass()); assertEquals(NumberEval.class, result.getClass());
assertEquals(expected, ((NumberEval)result).getNumberValue(), 0); assertEquals(expected, ((NumberEval)result).getNumberValue(), 0);
} }
private void confirmLen(Eval text, ErrorEval expectedError) { private void confirmLen(ValueEval text, ErrorEval expectedError) {
Eval result = invokeLen(text); ValueEval result = invokeLen(text);
assertEquals(ErrorEval.class, result.getClass()); assertEquals(ErrorEval.class, result.getClass());
assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode()); assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
} }

View File

@ -22,7 +22,6 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.record.formula.eval.AreaEval; import org.apache.poi.hssf.record.formula.eval.AreaEval;
import org.apache.poi.hssf.record.formula.eval.BoolEval; 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.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval; import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
import org.apache.poi.hssf.record.formula.eval.StringEval; import org.apache.poi.hssf.record.formula.eval.StringEval;
@ -41,11 +40,11 @@ public final class TestMatch extends TestCase {
private static final NumberEval MATCH_SMALLEST_GTE = new NumberEval(-1); private static final NumberEval MATCH_SMALLEST_GTE = new NumberEval(-1);
private static Eval invokeMatch(Eval lookup_value, Eval lookup_array, Eval match_type) { private static ValueEval invokeMatch(ValueEval lookup_value, ValueEval lookup_array, ValueEval match_type) {
Eval[] args = { lookup_value, lookup_array, match_type, }; ValueEval[] args = { lookup_value, lookup_array, match_type, };
return new Match().evaluate(args, -1, (short)-1); return new Match().evaluate(args, -1, (short)-1);
} }
private static void confirmInt(int expected, Eval actualEval) { private static void confirmInt(int expected, ValueEval actualEval) {
if(!(actualEval instanceof NumericValueEval)) { if(!(actualEval instanceof NumericValueEval)) {
fail("Expected numeric result"); fail("Expected numeric result");
} }

View File

@ -23,7 +23,6 @@ import org.apache.poi.hssf.record.formula.eval.AreaEval;
import org.apache.poi.hssf.record.formula.eval.BlankEval; import org.apache.poi.hssf.record.formula.eval.BlankEval;
import org.apache.poi.hssf.record.formula.eval.BoolEval; 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.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.RefEval; import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.StringEval; import org.apache.poi.hssf.record.formula.eval.StringEval;
@ -36,19 +35,19 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval;
public final class TestMid extends TestCase { public final class TestMid extends TestCase {
private static Eval invokeMid(Eval text, Eval startPos, Eval numChars) { private static ValueEval invokeMid(ValueEval text, ValueEval startPos, ValueEval numChars) {
Eval[] args = new Eval[] { text, startPos, numChars, }; ValueEval[] args = new ValueEval[] { text, startPos, numChars, };
return TextFunction.MID.evaluate(args, -1, (short)-1); return TextFunction.MID.evaluate(args, -1, (short)-1);
} }
private void confirmMid(Eval text, Eval startPos, Eval numChars, String expected) { private void confirmMid(ValueEval text, ValueEval startPos, ValueEval numChars, String expected) {
Eval result = invokeMid(text, startPos, numChars); ValueEval result = invokeMid(text, startPos, numChars);
assertEquals(StringEval.class, result.getClass()); assertEquals(StringEval.class, result.getClass());
assertEquals(expected, ((StringEval)result).getStringValue()); assertEquals(expected, ((StringEval)result).getStringValue());
} }
private void confirmMid(Eval text, Eval startPos, Eval numChars, ErrorEval expectedError) { private void confirmMid(ValueEval text, ValueEval startPos, ValueEval numChars, ErrorEval expectedError) {
Eval result = invokeMid(text, startPos, numChars); ValueEval result = invokeMid(text, startPos, numChars);
assertEquals(ErrorEval.class, result.getClass()); assertEquals(ErrorEval.class, result.getClass());
assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode()); assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
} }

View File

@ -19,8 +19,8 @@ package org.apache.poi.hssf.record.formula.functions;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.usermodel.HSSFCell; import org.apache.poi.hssf.usermodel.HSSFCell;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants; import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator; import org.apache.poi.hssf.usermodel.HSSFFormulaEvaluator;
@ -35,12 +35,12 @@ import org.apache.poi.hssf.usermodel.HSSFWorkbook;
public final class TestNper extends TestCase { public final class TestNper extends TestCase {
public void testSimpleEvaluate() { public void testSimpleEvaluate() {
Eval[] args = { ValueEval[] args = {
new NumberEval(0.05), new NumberEval(0.05),
new NumberEval(250), new NumberEval(250),
new NumberEval(-1000), new NumberEval(-1000),
}; };
Eval result = FinanceFunction.NPER.evaluate(args, 0, (short)0); ValueEval result = FinanceFunction.NPER.evaluate(args, 0, (short)0);
assertEquals(NumberEval.class, result.getClass()); assertEquals(NumberEval.class, result.getClass());
assertEquals(4.57353557, ((NumberEval)result).getNumberValue(), 0.00000001); assertEquals(4.57353557, ((NumberEval)result).getNumberValue(), 0.00000001);

View File

@ -21,12 +21,11 @@ import junit.framework.AssertionFailedError;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.usermodel.HSSFErrorConstants; import org.apache.poi.hssf.usermodel.HSSFErrorConstants;
/** /**
*
* @author Josh Micich * @author Josh Micich
*/ */
public final class TestPmt extends TestCase { public final class TestPmt extends TestCase {
@ -35,14 +34,14 @@ public final class TestPmt extends TestCase {
// only asserting accuracy to 4 fractional digits // only asserting accuracy to 4 fractional digits
assertEquals(expected, ne.getNumberValue(), 0.00005); assertEquals(expected, ne.getNumberValue(), 0.00005);
} }
private static Eval invoke(Eval[] args) { private static ValueEval invoke(ValueEval[] args) {
return FinanceFunction.PMT.evaluate(args, -1, (short)-1); return FinanceFunction.PMT.evaluate(args, -1, (short)-1);
} }
/** /**
* Invocation when not expecting an error result * Invocation when not expecting an error result
*/ */
private static NumberEval invokeNormal(Eval[] args) { private static NumberEval invokeNormal(ValueEval[] args) {
Eval ev = invoke(args); ValueEval ev = invoke(args);
if(ev instanceof ErrorEval) { if(ev instanceof ErrorEval) {
throw new AssertionFailedError("Normal evaluation failed with error code: " throw new AssertionFailedError("Normal evaluation failed with error code: "
+ ev.toString()); + ev.toString());
@ -51,7 +50,7 @@ public final class TestPmt extends TestCase {
} }
private static void confirm(double expected, double rate, double nper, double pv, double fv, boolean isBeginning) { private static void confirm(double expected, double rate, double nper, double pv, double fv, boolean isBeginning) {
Eval[] args = { ValueEval[] args = {
new NumberEval(rate), new NumberEval(rate),
new NumberEval(nper), new NumberEval(nper),
new NumberEval(pv), new NumberEval(pv),
@ -69,12 +68,12 @@ public final class TestPmt extends TestCase {
public void test3args() { public void test3args() {
Eval[] args = { ValueEval[] args = {
new NumberEval(0.005), new NumberEval(0.005),
new NumberEval(24), new NumberEval(24),
new NumberEval(1000), new NumberEval(1000),
}; };
Eval ev = invoke(args); ValueEval ev = invoke(args);
if(ev instanceof ErrorEval) { if(ev instanceof ErrorEval) {
ErrorEval err = (ErrorEval) ev; ErrorEval err = (ErrorEval) ev;
if(err.getErrorCode() == HSSFErrorConstants.ERROR_VALUE) { if(err.getErrorCode() == HSSFErrorConstants.ERROR_VALUE) {

View File

@ -20,7 +20,7 @@ package org.apache.poi.hssf.record.formula.functions;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.StringEval; import org.apache.poi.hssf.record.formula.eval.StringEval;
@ -33,17 +33,17 @@ public final class TestRoundFuncs extends TestCase {
private static final NumericFunction F = null; private static final NumericFunction F = null;
public void testRounddownWithStringArg() { public void testRounddownWithStringArg() {
Eval strArg = new StringEval("abc"); ValueEval strArg = new StringEval("abc");
Eval[] args = { strArg, new NumberEval(2), }; ValueEval[] args = { strArg, new NumberEval(2), };
Eval result = F.ROUNDDOWN.evaluate(args, -1, (short)-1); ValueEval result = F.ROUNDDOWN.evaluate(args, -1, (short)-1);
assertEquals(ErrorEval.VALUE_INVALID, result); assertEquals(ErrorEval.VALUE_INVALID, result);
} }
public void testRoundupWithStringArg() { public void testRoundupWithStringArg() {
Eval strArg = new StringEval("abc"); ValueEval strArg = new StringEval("abc");
Eval[] args = { strArg, new NumberEval(2), }; ValueEval[] args = { strArg, new NumberEval(2), };
Eval result = F.ROUNDUP.evaluate(args, -1, (short)-1); ValueEval result = F.ROUNDUP.evaluate(args, -1, (short)-1);
assertEquals(ErrorEval.VALUE_INVALID, result); assertEquals(ErrorEval.VALUE_INVALID, result);
} }

View File

@ -21,7 +21,6 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.record.formula.eval.AreaEval; import org.apache.poi.hssf.record.formula.eval.AreaEval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval; import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
import org.apache.poi.hssf.record.formula.eval.RefEval; import org.apache.poi.hssf.record.formula.eval.RefEval;
@ -34,11 +33,11 @@ import org.apache.poi.hssf.record.formula.eval.ValueEval;
*/ */
public final class TestSumproduct extends TestCase { public final class TestSumproduct extends TestCase {
private static Eval invokeSumproduct(Eval[] args) { private static ValueEval invokeSumproduct(ValueEval[] args) {
// srcCellRow and srcCellColumn are ignored by SUMPRODUCT // srcCellRow and srcCellColumn are ignored by SUMPRODUCT
return new Sumproduct().evaluate(args, -1, (short)-1); return new Sumproduct().evaluate(args, -1, (short)-1);
} }
private static void confirmDouble(double expected, Eval actualEval) { private static void confirmDouble(double expected, ValueEval actualEval) {
if(!(actualEval instanceof NumericValueEval)) { if(!(actualEval instanceof NumericValueEval)) {
fail("Expected numeric result"); fail("Expected numeric result");
} }
@ -49,11 +48,11 @@ public final class TestSumproduct extends TestCase {
public void testScalarSimple() { public void testScalarSimple() {
RefEval refEval = EvalFactory.createRefEval("A1", new NumberEval(3)); RefEval refEval = EvalFactory.createRefEval("A1", new NumberEval(3));
Eval[] args = { ValueEval[] args = {
refEval, refEval,
new NumberEval(2), new NumberEval(2),
}; };
Eval result = invokeSumproduct(args); ValueEval result = invokeSumproduct(args);
confirmDouble(6D, result); confirmDouble(6D, result);
} }
@ -71,8 +70,8 @@ public final class TestSumproduct extends TestCase {
AreaEval aeA = EvalFactory.createAreaEval("A1:A3", aValues); AreaEval aeA = EvalFactory.createAreaEval("A1:A3", aValues);
AreaEval aeB = EvalFactory.createAreaEval("B1:B3", bValues); AreaEval aeB = EvalFactory.createAreaEval("B1:B3", bValues);
Eval[] args = { aeA, aeB, }; ValueEval[] args = { aeA, aeB, };
Eval result = invokeSumproduct(args); ValueEval result = invokeSumproduct(args);
confirmDouble(65D, result); confirmDouble(65D, result);
} }
@ -83,11 +82,11 @@ public final class TestSumproduct extends TestCase {
AreaEval ae = EvalFactory.createAreaEval("A1:A1", new ValueEval[] { new NumberEval(7), }); AreaEval ae = EvalFactory.createAreaEval("A1:A1", new ValueEval[] { new NumberEval(7), });
Eval[] args = { ValueEval[] args = {
ae, ae,
new NumberEval(2), new NumberEval(2),
}; };
Eval result = invokeSumproduct(args); ValueEval result = invokeSumproduct(args);
confirmDouble(14D, result); confirmDouble(14D, result);
} }
@ -96,11 +95,11 @@ public final class TestSumproduct extends TestCase {
AreaEval aeA = EvalFactory.createAreaEval("A1:A3", new ValueEval[3]); AreaEval aeA = EvalFactory.createAreaEval("A1:A3", new ValueEval[3]);
AreaEval aeB = EvalFactory.createAreaEval("B1:D1", new ValueEval[3]); AreaEval aeB = EvalFactory.createAreaEval("B1:D1", new ValueEval[3]);
Eval[] args; ValueEval[] args;
args = new Eval[] { aeA, aeB, }; args = new ValueEval[] { aeA, aeB, };
assertEquals(ErrorEval.VALUE_INVALID, invokeSumproduct(args)); assertEquals(ErrorEval.VALUE_INVALID, invokeSumproduct(args));
args = new Eval[] { aeA, new NumberEval(5), }; args = new ValueEval[] { aeA, new NumberEval(5), };
assertEquals(ErrorEval.VALUE_INVALID, invokeSumproduct(args)); assertEquals(ErrorEval.VALUE_INVALID, invokeSumproduct(args));
} }
@ -112,7 +111,7 @@ public final class TestSumproduct extends TestCase {
AreaEval aeA = EvalFactory.createAreaEval("A1:A2", aValues); AreaEval aeA = EvalFactory.createAreaEval("A1:A2", aValues);
AreaEval aeB = EvalFactory.createAreaEval("B1:B2", new ValueEval[2]); AreaEval aeB = EvalFactory.createAreaEval("B1:B2", new ValueEval[2]);
Eval[] args = { aeA, aeB, }; ValueEval[] args = { aeA, aeB, };
assertEquals(ErrorEval.REF_INVALID, invokeSumproduct(args)); assertEquals(ErrorEval.REF_INVALID, invokeSumproduct(args));
} }
} }

View File

@ -22,7 +22,6 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.record.formula.eval.BlankEval; import org.apache.poi.hssf.record.formula.eval.BlankEval;
import org.apache.poi.hssf.record.formula.eval.BoolEval; 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.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.StringEval; import org.apache.poi.hssf.record.formula.eval.StringEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
@ -37,9 +36,9 @@ public final class TestTFunc extends TestCase {
/** /**
* @return the result of calling function T() with the specified argument * @return the result of calling function T() with the specified argument
*/ */
private static Eval invokeT(Eval arg) { private static ValueEval invokeT(ValueEval arg) {
Eval[] args = { arg, }; ValueEval[] args = { arg, };
Eval result = new T().evaluate(args, -1, (short)-1); ValueEval result = new T().evaluate(args, -1, (short)-1);
assertNotNull("result may never be null", result); assertNotNull("result may never be null", result);
return result; return result;
} }
@ -47,14 +46,14 @@ public final class TestTFunc extends TestCase {
* Simulates call: T(A1) * Simulates call: T(A1)
* where cell A1 has the specified innerValue * where cell A1 has the specified innerValue
*/ */
private Eval invokeTWithReference(ValueEval innerValue) { private ValueEval invokeTWithReference(ValueEval innerValue) {
Eval arg = EvalFactory.createRefEval("$B$2", innerValue); ValueEval arg = EvalFactory.createRefEval("$B$2", innerValue);
return invokeT(arg); return invokeT(arg);
} }
private static void confirmText(String text) { private static void confirmText(String text) {
Eval arg = new StringEval(text); ValueEval arg = new StringEval(text);
Eval eval = invokeT(arg); ValueEval eval = invokeT(arg);
StringEval se = (StringEval) eval; StringEval se = (StringEval) eval;
assertEquals(text, se.getStringValue()); assertEquals(text, se.getStringValue());
} }
@ -69,8 +68,8 @@ public final class TestTFunc extends TestCase {
confirmText("TRUE"); confirmText("TRUE");
} }
private static void confirmError(Eval arg) { private static void confirmError(ValueEval arg) {
Eval eval = invokeT(arg); ValueEval eval = invokeT(arg);
assertTrue(arg == eval); assertTrue(arg == eval);
} }
@ -81,13 +80,13 @@ public final class TestTFunc extends TestCase {
confirmError(ErrorEval.REF_INVALID); confirmError(ErrorEval.REF_INVALID);
} }
private static void confirmString(Eval eval, String expected) { private static void confirmString(ValueEval eval, String expected) {
assertTrue(eval instanceof StringEval); assertTrue(eval instanceof StringEval);
assertEquals(expected, ((StringEval)eval).getStringValue()); assertEquals(expected, ((StringEval)eval).getStringValue());
} }
private static void confirmOther(Eval arg) { private static void confirmOther(ValueEval arg) {
Eval eval = invokeT(arg); ValueEval eval = invokeT(arg);
confirmString(eval, ""); confirmString(eval, "");
} }
@ -98,7 +97,7 @@ public final class TestTFunc extends TestCase {
} }
public void testRefValues() { public void testRefValues() {
Eval eval; ValueEval eval;
eval = invokeTWithReference(new StringEval("def")); eval = invokeTWithReference(new StringEval("def"));
confirmString(eval, "def"); confirmString(eval, "def");

View File

@ -22,9 +22,9 @@ import junit.framework.TestCase;
import org.apache.poi.hssf.record.formula.eval.BlankEval; import org.apache.poi.hssf.record.formula.eval.BlankEval;
import org.apache.poi.hssf.record.formula.eval.BoolEval; 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.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.StringEval; import org.apache.poi.hssf.record.formula.eval.StringEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
/** /**
* Tests for Excel function TRIM() * Tests for Excel function TRIM()
* *
@ -33,19 +33,19 @@ import org.apache.poi.hssf.record.formula.eval.StringEval;
public final class TestTrim extends TestCase { public final class TestTrim extends TestCase {
private static Eval invokeTrim(Eval text) { private static ValueEval invokeTrim(ValueEval text) {
Eval[] args = new Eval[] { text, }; ValueEval[] args = new ValueEval[] { text, };
return TextFunction.TRIM.evaluate(args, -1, (short)-1); return TextFunction.TRIM.evaluate(args, -1, (short)-1);
} }
private void confirmTrim(Eval text, String expected) { private void confirmTrim(ValueEval text, String expected) {
Eval result = invokeTrim(text); ValueEval result = invokeTrim(text);
assertEquals(StringEval.class, result.getClass()); assertEquals(StringEval.class, result.getClass());
assertEquals(expected, ((StringEval)result).getStringValue()); assertEquals(expected, ((StringEval)result).getStringValue());
} }
private void confirmTrim(Eval text, ErrorEval expectedError) { private void confirmTrim(ValueEval text, ErrorEval expectedError) {
Eval result = invokeTrim(text); ValueEval result = invokeTrim(text);
assertEquals(ErrorEval.class, result.getClass()); assertEquals(ErrorEval.class, result.getClass());
assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode()); assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
} }

View File

@ -20,9 +20,9 @@ package org.apache.poi.hssf.record.formula.functions;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.StringEval; import org.apache.poi.hssf.record.formula.eval.StringEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
/** /**
* Tests for {@link Value} * Tests for {@link Value}
@ -31,19 +31,19 @@ import org.apache.poi.hssf.record.formula.eval.StringEval;
*/ */
public final class TestValue extends TestCase { public final class TestValue extends TestCase {
private static Eval invokeValue(String strText) { private static ValueEval invokeValue(String strText) {
Eval[] args = new Eval[] { new StringEval(strText), }; ValueEval[] args = new ValueEval[] { new StringEval(strText), };
return new Value().evaluate(args, -1, (short) -1); return new Value().evaluate(args, -1, (short) -1);
} }
private static void confirmValue(String strText, double expected) { private static void confirmValue(String strText, double expected) {
Eval result = invokeValue(strText); ValueEval result = invokeValue(strText);
assertEquals(NumberEval.class, result.getClass()); assertEquals(NumberEval.class, result.getClass());
assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.0); assertEquals(expected, ((NumberEval) result).getNumberValue(), 0.0);
} }
private static void confirmValueError(String strText) { private static void confirmValueError(String strText) {
Eval result = invokeValue(strText); ValueEval result = invokeValue(strText);
assertEquals(ErrorEval.class, result.getClass()); assertEquals(ErrorEval.class, result.getClass());
assertEquals(ErrorEval.VALUE_INVALID, result); assertEquals(ErrorEval.VALUE_INVALID, result);
} }

View File

@ -20,7 +20,6 @@ package org.apache.poi.hssf.record.formula.functions;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.poi.hssf.record.formula.eval.ErrorEval; import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.NumberEval; import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval; import org.apache.poi.hssf.record.formula.eval.ValueEval;
/** /**
@ -33,23 +32,23 @@ public final class TestXYNumericFunction extends TestCase {
private static final Function DIFF_SQUARES = new Sumx2my2(); private static final Function DIFF_SQUARES = new Sumx2my2();
private static final Function SUM_SQUARES_OF_DIFFS = new Sumxmy2(); private static final Function SUM_SQUARES_OF_DIFFS = new Sumxmy2();
private static Eval invoke(Function function, Eval xArray, Eval yArray) { private static ValueEval invoke(Function function, ValueEval xArray, ValueEval yArray) {
Eval[] args = new Eval[] { xArray, yArray, }; ValueEval[] args = new ValueEval[] { xArray, yArray, };
return function.evaluate(args, -1, (short)-1); return function.evaluate(args, -1, (short)-1);
} }
private void confirm(Function function, Eval xArray, Eval yArray, double expected) { private void confirm(Function function, ValueEval xArray, ValueEval yArray, double expected) {
Eval result = invoke(function, xArray, yArray); ValueEval result = invoke(function, xArray, yArray);
assertEquals(NumberEval.class, result.getClass()); assertEquals(NumberEval.class, result.getClass());
assertEquals(expected, ((NumberEval)result).getNumberValue(), 0); assertEquals(expected, ((NumberEval)result).getNumberValue(), 0);
} }
private void confirmError(Function function, Eval xArray, Eval yArray, ErrorEval expectedError) { private void confirmError(Function function, ValueEval xArray, ValueEval yArray, ErrorEval expectedError) {
Eval result = invoke(function, xArray, yArray); ValueEval result = invoke(function, xArray, yArray);
assertEquals(ErrorEval.class, result.getClass()); assertEquals(ErrorEval.class, result.getClass());
assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode()); assertEquals(expectedError.getErrorCode(), ((ErrorEval)result).getErrorCode());
} }
private void confirmError(Eval xArray, Eval yArray, ErrorEval expectedError) { private void confirmError(ValueEval xArray, ValueEval yArray, ErrorEval expectedError) {
confirmError(SUM_SQUARES, xArray, yArray, expectedError); confirmError(SUM_SQUARES, xArray, yArray, expectedError);
confirmError(DIFF_SQUARES, xArray, yArray, expectedError); confirmError(DIFF_SQUARES, xArray, yArray, expectedError);
confirmError(SUM_SQUARES_OF_DIFFS, xArray, yArray, expectedError); confirmError(SUM_SQUARES_OF_DIFFS, xArray, yArray, expectedError);
@ -132,6 +131,5 @@ public final class TestXYNumericFunction extends TestCase {
// search for errors array by array, not pair by pair // search for errors array by array, not pair by pair
confirmError(areaEvalX, areaEvalY, ErrorEval.REF_INVALID); confirmError(areaEvalX, areaEvalY, ErrorEval.REF_INVALID);
confirmError(areaEvalY, areaEvalX, ErrorEval.NULL_INTERSECTION); confirmError(areaEvalY, areaEvalX, ErrorEval.NULL_INTERSECTION);
} }
} }