mirror of https://github.com/apache/poi.git
initial work on removing obsolete Eval interface
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@805091 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
f4c028c5a3
commit
6d65572fa8
|
@ -35,7 +35,7 @@ public final class AnalysisToolPak {
|
||||||
_functionName = functionName;
|
_functionName = functionName;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEval evaluate(Eval[] args, EvaluationWorkbook workbook, int srcCellSheet,
|
public ValueEval evaluate(ValueEval[] args, EvaluationWorkbook workbook, int srcCellSheet,
|
||||||
int srcCellRow, int srcCellCol) {
|
int srcCellRow, int srcCellCol) {
|
||||||
throw new NotImplementedException(_functionName);
|
throw new NotImplementedException(_functionName);
|
||||||
}
|
}
|
||||||
|
|
|
@ -40,7 +40,7 @@ final class ParityFunction implements FreeRefFunction {
|
||||||
_desiredParity = desiredParity;
|
_desiredParity = desiredParity;
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEval evaluate(Eval[] args, EvaluationWorkbook workbook, int srcCellSheet, int srcCellRow,
|
public ValueEval evaluate(ValueEval[] args, EvaluationWorkbook workbook, int srcCellSheet, int srcCellRow,
|
||||||
int srcCellCol) {
|
int srcCellCol) {
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
return ErrorEval.VALUE_INVALID;
|
return ErrorEval.VALUE_INVALID;
|
||||||
|
|
|
@ -59,7 +59,7 @@ final class YearFrac implements FreeRefFunction {
|
||||||
// enforce singleton
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEval evaluate(Eval[] args, EvaluationWorkbook workbook, int srcCellSheet, int srcCellRow,
|
public ValueEval evaluate(ValueEval[] args, EvaluationWorkbook workbook, int srcCellSheet, int srcCellRow,
|
||||||
int srcCellCol) {
|
int srcCellCol) {
|
||||||
|
|
||||||
double result;
|
double result;
|
||||||
|
|
|
@ -28,7 +28,7 @@ public final class ConcatEval implements OperationEval {
|
||||||
// enforce singleton
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public Eval evaluate(Eval[] args, int srcRow, short srcCol) {
|
public ValueEval evaluate(ValueEval[] args, int srcRow, short srcCol) {
|
||||||
if(args.length != 2) {
|
if(args.length != 2) {
|
||||||
return ErrorEval.VALUE_INVALID;
|
return ErrorEval.VALUE_INVALID;
|
||||||
}
|
}
|
||||||
|
|
|
@ -243,12 +243,12 @@ public final class FunctionEval implements OperationEval {
|
||||||
_delegate = funcPtg;
|
_delegate = funcPtg;
|
||||||
}
|
}
|
||||||
|
|
||||||
public Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
public ValueEval evaluate(ValueEval[] operands, int srcRow, short srcCol) {
|
||||||
Function f = getFunction();
|
Function f = getFunction();
|
||||||
if (f == null) {
|
if (f == null) {
|
||||||
throw new NotImplementedException("FuncIx=" + getFunctionIndex());
|
throw new NotImplementedException("FuncIx=" + getFunctionIndex());
|
||||||
}
|
}
|
||||||
return f.evaluate(operands, srcRow, srcCol);
|
return (ValueEval) f.evaluate(operands, srcRow, srcCol);
|
||||||
}
|
}
|
||||||
|
|
||||||
public int getNumberOfOperands() {
|
public int getNumberOfOperands() {
|
||||||
|
|
|
@ -33,7 +33,7 @@ public interface OperationEval {
|
||||||
* @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>.
|
||||||
*/
|
*/
|
||||||
Eval evaluate(Eval[] args, int srcRowIndex, short srcColumnIndex);
|
ValueEval evaluate(ValueEval[] args, int srcRowIndex, short srcColumnIndex);
|
||||||
|
|
||||||
int getNumberOfOperands();
|
int getNumberOfOperands();
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public final class PercentEval implements OperationEval {
|
||||||
// enforce singleton
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public Eval evaluate(Eval[] args, int srcRow, short srcCol) {
|
public ValueEval evaluate(ValueEval[] args, int srcRow, short srcCol) {
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
return ErrorEval.VALUE_INVALID;
|
return ErrorEval.VALUE_INVALID;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public final class RangeEval implements OperationEval {
|
||||||
// enforces singleton
|
// enforces singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) {
|
public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
|
||||||
if(args.length != 2) {
|
if(args.length != 2) {
|
||||||
return ErrorEval.VALUE_INVALID;
|
return ErrorEval.VALUE_INVALID;
|
||||||
}
|
}
|
||||||
|
|
|
@ -54,7 +54,7 @@ public abstract class RelationalOperationEval implements OperationEval {
|
||||||
* Blank < Positive numbers
|
* Blank < Positive numbers
|
||||||
* </pre>
|
* </pre>
|
||||||
*/
|
*/
|
||||||
public final Eval evaluate(Eval[] operands, int srcRow, short srcCol) {
|
public final ValueEval evaluate(ValueEval[] operands, int srcRow, short srcCol) {
|
||||||
if (operands.length != 2) {
|
if (operands.length != 2) {
|
||||||
return ErrorEval.VALUE_INVALID;
|
return ErrorEval.VALUE_INVALID;
|
||||||
}
|
}
|
||||||
|
|
|
@ -27,7 +27,7 @@ abstract class TwoOperandNumericOperation implements OperationEval {
|
||||||
return OperandResolver.coerceValueToDouble(ve);
|
return OperandResolver.coerceValueToDouble(ve);
|
||||||
}
|
}
|
||||||
|
|
||||||
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 {
|
||||||
double d0 = singleOperandEvaluate(args[0], srcCellRow, srcCellCol);
|
double d0 = singleOperandEvaluate(args[0], srcCellRow, srcCellCol);
|
||||||
|
|
|
@ -30,7 +30,7 @@ public final class UnaryMinusEval implements OperationEval {
|
||||||
// enforce singleton
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public Eval evaluate(Eval[] args, int srcRow, short srcCol) {
|
public ValueEval evaluate(ValueEval[] args, int srcRow, short srcCol) {
|
||||||
if (args.length != 1) {
|
if (args.length != 1) {
|
||||||
return ErrorEval.VALUE_INVALID;
|
return ErrorEval.VALUE_INVALID;
|
||||||
}
|
}
|
||||||
|
|
|
@ -30,7 +30,7 @@ public final class UnaryPlusEval implements OperationEval {
|
||||||
// enforce singleton
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
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;
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,7 @@ final class UserDefinedFunction implements FreeRefFunction {
|
||||||
// enforce singleton
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEval evaluate(Eval[] args, EvaluationWorkbook workbook,
|
public ValueEval evaluate(ValueEval[] args, EvaluationWorkbook workbook,
|
||||||
int srcCellSheet, int srcCellRow,int srcCellCol) {
|
int srcCellSheet, int srcCellRow,int srcCellCol) {
|
||||||
|
|
||||||
int nIncomingArgs = args.length;
|
int nIncomingArgs = args.length;
|
||||||
|
@ -55,7 +55,7 @@ final class UserDefinedFunction implements FreeRefFunction {
|
||||||
+ nameArg.getClass().getName() + ")");
|
+ nameArg.getClass().getName() + ")");
|
||||||
}
|
}
|
||||||
int nOutGoingArgs = nIncomingArgs -1;
|
int nOutGoingArgs = nIncomingArgs -1;
|
||||||
Eval[] outGoingArgs = new Eval[nOutGoingArgs];
|
ValueEval[] outGoingArgs = new ValueEval[nOutGoingArgs];
|
||||||
System.arraycopy(args, 1, outGoingArgs, 0, nOutGoingArgs);
|
System.arraycopy(args, 1, outGoingArgs, 0, nOutGoingArgs);
|
||||||
return targetFunc.evaluate(outGoingArgs, workbook, srcCellSheet, srcCellRow, srcCellCol);
|
return targetFunc.evaluate(outGoingArgs, workbook, srcCellSheet, srcCellRow, srcCellCol);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,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.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
||||||
import org.apache.poi.ss.formula.EvaluationWorkbook;
|
import org.apache.poi.ss.formula.EvaluationWorkbook;
|
||||||
|
|
||||||
|
@ -52,5 +51,5 @@ public interface FreeRefFunction {
|
||||||
* a specified Excel error (Exceptions are never thrown to represent Excel errors).
|
* a specified Excel error (Exceptions are never thrown to represent Excel errors).
|
||||||
*
|
*
|
||||||
*/
|
*/
|
||||||
ValueEval evaluate(Eval[] args, EvaluationWorkbook workbook, int srcCellSheet, int srcCellRow, int srcCellCol);
|
ValueEval evaluate(ValueEval[] args, EvaluationWorkbook workbook, int srcCellSheet, int srcCellRow, int srcCellCol);
|
||||||
}
|
}
|
||||||
|
|
|
@ -17,7 +17,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.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
||||||
import org.apache.poi.ss.formula.EvaluationWorkbook;
|
import org.apache.poi.ss.formula.EvaluationWorkbook;
|
||||||
import org.apache.poi.ss.formula.eval.NotImplementedException;
|
import org.apache.poi.ss.formula.eval.NotImplementedException;
|
||||||
|
@ -46,7 +45,7 @@ public final class Indirect implements FreeRefFunction {
|
||||||
// enforce singleton
|
// enforce singleton
|
||||||
}
|
}
|
||||||
|
|
||||||
public ValueEval evaluate(Eval[] args, EvaluationWorkbook workbook, int srcCellSheet, int srcCellRow, int srcCellCol) {
|
public ValueEval evaluate(ValueEval[] args, EvaluationWorkbook workbook, int srcCellSheet, int srcCellRow, int srcCellCol) {
|
||||||
// TODO - implement INDIRECT()
|
// TODO - implement INDIRECT()
|
||||||
throw new NotImplementedException("INDIRECT");
|
throw new NotImplementedException("INDIRECT");
|
||||||
}
|
}
|
||||||
|
|
|
@ -51,7 +51,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.FunctionEval;
|
import org.apache.poi.hssf.record.formula.eval.FunctionEval;
|
||||||
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.NameEval;
|
import org.apache.poi.hssf.record.formula.eval.NameEval;
|
||||||
|
@ -385,7 +384,7 @@ public final class WorkbookEvaluator {
|
||||||
return evaluationResult;
|
return evaluationResult;
|
||||||
}
|
}
|
||||||
|
|
||||||
private static ValueEval invokeOperation(OperationEval operation, Eval[] ops,
|
private static ValueEval invokeOperation(OperationEval operation, ValueEval[] ops,
|
||||||
EvaluationWorkbook workbook, int sheetIndex, int srcRowNum, int srcColNum) {
|
EvaluationWorkbook workbook, int sheetIndex, int srcRowNum, int srcColNum) {
|
||||||
|
|
||||||
if(operation instanceof FunctionEval) {
|
if(operation instanceof FunctionEval) {
|
||||||
|
|
|
@ -30,7 +30,7 @@ import org.apache.poi.hssf.record.formula.functions.NumericFunctionInvoker;
|
||||||
public final class TestDivideEval extends TestCase {
|
public final class TestDivideEval extends TestCase {
|
||||||
|
|
||||||
private static void confirm(ValueEval arg0, ValueEval arg1, double expectedResult) {
|
private static void confirm(ValueEval arg0, ValueEval arg1, double expectedResult) {
|
||||||
Eval[] args = {
|
ValueEval[] args = {
|
||||||
arg0, arg1,
|
arg0, arg1,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -53,10 +53,10 @@ public final class TestDivideEval extends TestCase {
|
||||||
confirm(ae0, ae1, 5);
|
confirm(ae0, ae1, 5);
|
||||||
}
|
}
|
||||||
public void testDivZero() {
|
public void testDivZero() {
|
||||||
Eval[] args = {
|
ValueEval[] args = {
|
||||||
new NumberEval(5), NumberEval.ZERO,
|
new NumberEval(5), NumberEval.ZERO,
|
||||||
};
|
};
|
||||||
Eval result = DivideEval.instance.evaluate(args, 0, (short) 0);
|
ValueEval result = DivideEval.instance.evaluate(args, 0, (short) 0);
|
||||||
assertEquals(ErrorEval.DIV_ZERO, result);
|
assertEquals(ErrorEval.DIV_ZERO, result);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,11 +36,11 @@ public final class TestEqualEval extends TestCase {
|
||||||
public void test1x1AreaOperand() {
|
public void test1x1AreaOperand() {
|
||||||
|
|
||||||
ValueEval[] values = { BoolEval.FALSE, };
|
ValueEval[] values = { BoolEval.FALSE, };
|
||||||
Eval[] args = {
|
ValueEval[] args = {
|
||||||
EvalFactory.createAreaEval("B1:B1", values),
|
EvalFactory.createAreaEval("B1:B1", values),
|
||||||
BoolEval.FALSE,
|
BoolEval.FALSE,
|
||||||
};
|
};
|
||||||
Eval result = EqualEval.instance.evaluate(args, 10, (short)20);
|
ValueEval result = EqualEval.instance.evaluate(args, 10, (short)20);
|
||||||
if (result instanceof ErrorEval) {
|
if (result instanceof ErrorEval) {
|
||||||
if (result == ErrorEval.VALUE_INVALID) {
|
if (result == ErrorEval.VALUE_INVALID) {
|
||||||
throw new AssertionFailedError("Identified bug in evaluation of 1x1 area");
|
throw new AssertionFailedError("Identified bug in evaluation of 1x1 area");
|
||||||
|
@ -54,11 +54,11 @@ public final class TestEqualEval extends TestCase {
|
||||||
*/
|
*/
|
||||||
public void testBlankEqualToEmptyString() {
|
public void testBlankEqualToEmptyString() {
|
||||||
|
|
||||||
Eval[] args = {
|
ValueEval[] args = {
|
||||||
new StringEval(""),
|
new StringEval(""),
|
||||||
BlankEval.INSTANCE,
|
BlankEval.INSTANCE,
|
||||||
};
|
};
|
||||||
Eval result = EqualEval.instance.evaluate(args, 10, (short)20);
|
ValueEval result = EqualEval.instance.evaluate(args, 10, (short)20);
|
||||||
assertEquals(BoolEval.class, result.getClass());
|
assertEquals(BoolEval.class, result.getClass());
|
||||||
BoolEval be = (BoolEval) result;
|
BoolEval be = (BoolEval) result;
|
||||||
if (!be.getBooleanValue()) {
|
if (!be.getBooleanValue()) {
|
||||||
|
@ -82,11 +82,11 @@ public final class TestEqualEval extends TestCase {
|
||||||
}
|
}
|
||||||
|
|
||||||
private static boolean evalStringCmp(String a, String b, OperationEval cmpOp) {
|
private static boolean evalStringCmp(String a, String b, OperationEval cmpOp) {
|
||||||
Eval[] args = {
|
ValueEval[] args = {
|
||||||
new StringEval(a),
|
new StringEval(a),
|
||||||
new StringEval(b),
|
new StringEval(b),
|
||||||
};
|
};
|
||||||
Eval result = cmpOp.evaluate(args, 10, (short)20);
|
ValueEval result = cmpOp.evaluate(args, 10, (short)20);
|
||||||
assertEquals(BoolEval.class, result.getClass());
|
assertEquals(BoolEval.class, result.getClass());
|
||||||
BoolEval be = (BoolEval) result;
|
BoolEval be = (BoolEval) result;
|
||||||
return be.getBooleanValue();
|
return be.getBooleanValue();
|
||||||
|
@ -103,12 +103,12 @@ public final class TestEqualEval extends TestCase {
|
||||||
*/
|
*/
|
||||||
public void testZeroEquality_bug47198() {
|
public void testZeroEquality_bug47198() {
|
||||||
NumberEval zero = new NumberEval(0.0);
|
NumberEval zero = new NumberEval(0.0);
|
||||||
NumberEval mZero = (NumberEval) UnaryMinusEval.instance.evaluate(new Eval[] { zero, }, 0,
|
NumberEval mZero = (NumberEval) UnaryMinusEval.instance.evaluate(new ValueEval[] { zero, }, 0,
|
||||||
(short) 0);
|
(short) 0);
|
||||||
if (Double.doubleToLongBits(mZero.getNumberValue()) == 0x8000000000000000L) {
|
if (Double.doubleToLongBits(mZero.getNumberValue()) == 0x8000000000000000L) {
|
||||||
throw new AssertionFailedError("Identified bug 47198: unary minus should convert -0.0 to 0.0");
|
throw new AssertionFailedError("Identified bug 47198: unary minus should convert -0.0 to 0.0");
|
||||||
}
|
}
|
||||||
Eval[] args = { zero, mZero, };
|
ValueEval[] args = { zero, mZero, };
|
||||||
BoolEval result = (BoolEval) EqualEval.instance.evaluate(args, 0, (short) 0);
|
BoolEval result = (BoolEval) EqualEval.instance.evaluate(args, 0, (short) 0);
|
||||||
if (!result.getBooleanValue()) {
|
if (!result.getBooleanValue()) {
|
||||||
throw new AssertionFailedError("Identified bug 47198: -0.0 != 0.0");
|
throw new AssertionFailedError("Identified bug 47198: -0.0 != 0.0");
|
||||||
|
@ -123,7 +123,7 @@ public final class TestEqualEval extends TestCase {
|
||||||
NumberEval b = new NumberEval(1.0055);
|
NumberEval b = new NumberEval(1.0055);
|
||||||
assertEquals("1.0055", b.getStringValue());
|
assertEquals("1.0055", b.getStringValue());
|
||||||
|
|
||||||
Eval[] args = { a, b, };
|
ValueEval[] args = { a, b, };
|
||||||
BoolEval result = (BoolEval) EqualEval.instance.evaluate(args, 0, (short) 0);
|
BoolEval result = (BoolEval) EqualEval.instance.evaluate(args, 0, (short) 0);
|
||||||
if (!result.getBooleanValue()) {
|
if (!result.getBooleanValue()) {
|
||||||
throw new AssertionFailedError("Identified bug 47598: 1+1.0028-0.9973 != 1.0055");
|
throw new AssertionFailedError("Identified bug 47598: 1+1.0028-0.9973 != 1.0055");
|
||||||
|
|
|
@ -77,7 +77,7 @@ public final class TestMinusZeroResult extends TestCase {
|
||||||
* Uses {@link ConcatEval} to force number-to-text conversion
|
* Uses {@link ConcatEval} to force number-to-text conversion
|
||||||
*/
|
*/
|
||||||
private static void confirmTextRendering(String expRendering, double d) {
|
private static void confirmTextRendering(String expRendering, double d) {
|
||||||
Eval[] args = { StringEval.EMPTY_INSTANCE, new NumberEval(d), };
|
ValueEval[] args = { StringEval.EMPTY_INSTANCE, new NumberEval(d), };
|
||||||
StringEval se = (StringEval) ConcatEval.instance.evaluate(args, -1, (short)-1);
|
StringEval se = (StringEval) ConcatEval.instance.evaluate(args, -1, (short)-1);
|
||||||
String result = se.getStringValue();
|
String result = se.getStringValue();
|
||||||
assertEquals(expRendering, result);
|
assertEquals(expRendering, result);
|
||||||
|
@ -91,13 +91,13 @@ public final class TestMinusZeroResult extends TestCase {
|
||||||
BoolEval result = (BoolEval) evaluate(instance, dArgs);
|
BoolEval result = (BoolEval) evaluate(instance, dArgs);
|
||||||
assertEquals(expectedResult, result.getBooleanValue());
|
assertEquals(expectedResult, result.getBooleanValue());
|
||||||
}
|
}
|
||||||
private static Eval evaluate(OperationEval instance, double... dArgs) {
|
private static ValueEval evaluate(OperationEval instance, double... dArgs) {
|
||||||
Eval[] evalArgs;
|
ValueEval[] evalArgs;
|
||||||
evalArgs = new Eval[dArgs.length];
|
evalArgs = new ValueEval[dArgs.length];
|
||||||
for (int i = 0; i < evalArgs.length; i++) {
|
for (int i = 0; i < evalArgs.length; i++) {
|
||||||
evalArgs[i] = new NumberEval(dArgs[i]);
|
evalArgs[i] = new NumberEval(dArgs[i]);
|
||||||
}
|
}
|
||||||
Eval r = instance.evaluate(evalArgs, -1, (short)-1);
|
ValueEval r = instance.evaluate(evalArgs, -1, (short)-1);
|
||||||
return r;
|
return r;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -37,7 +37,7 @@ import org.apache.poi.ss.usermodel.CellValue;
|
||||||
public final class TestPercentEval extends TestCase {
|
public final class TestPercentEval extends TestCase {
|
||||||
|
|
||||||
private static void confirm(ValueEval arg, double expectedResult) {
|
private static void confirm(ValueEval arg, double expectedResult) {
|
||||||
Eval[] args = {
|
ValueEval[] args = {
|
||||||
arg,
|
arg,
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -81,5 +81,4 @@ public final class TestPercentEval extends TestCase {
|
||||||
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
|
assertEquals(HSSFCell.CELL_TYPE_NUMERIC, cv.getCellType());
|
||||||
assertEquals(0.5, cv.getNumberValue(), 0.0);
|
assertEquals(0.5, cv.getNumberValue(), 0.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -59,12 +59,12 @@ public final class TestRangeEval extends TestCase {
|
||||||
|
|
||||||
private static void confirm(String refA, String refB, String expectedAreaRef) {
|
private static void confirm(String refA, String refB, String expectedAreaRef) {
|
||||||
|
|
||||||
Eval[] args = {
|
ValueEval[] args = {
|
||||||
createRefEval(refA),
|
createRefEval(refA),
|
||||||
createRefEval(refB),
|
createRefEval(refB),
|
||||||
};
|
};
|
||||||
AreaReference ar = new AreaReference(expectedAreaRef);
|
AreaReference ar = new AreaReference(expectedAreaRef);
|
||||||
Eval result = RangeEval.instance.evaluate(args, 0, (short)0);
|
ValueEval result = RangeEval.instance.evaluate(args, 0, (short)0);
|
||||||
assertTrue(result instanceof AreaEval);
|
assertTrue(result instanceof AreaEval);
|
||||||
AreaEval ae = (AreaEval) result;
|
AreaEval ae = (AreaEval) result;
|
||||||
assertEquals(ar.getFirstCell().getRow(), ae.getFirstRow());
|
assertEquals(ar.getFirstCell().getRow(), ae.getFirstRow());
|
||||||
|
@ -73,7 +73,7 @@ public final class TestRangeEval extends TestCase {
|
||||||
assertEquals(ar.getLastCell().getCol(), ae.getLastColumn());
|
assertEquals(ar.getLastCell().getCol(), ae.getLastColumn());
|
||||||
}
|
}
|
||||||
|
|
||||||
private static Eval createRefEval(String refStr) {
|
private static ValueEval createRefEval(String refStr) {
|
||||||
CellReference cr = new CellReference(refStr);
|
CellReference cr = new CellReference(refStr);
|
||||||
return new MockRefEval(cr.getRow(), cr.getCol());
|
return new MockRefEval(cr.getRow(), cr.getCol());
|
||||||
|
|
||||||
|
|
|
@ -47,7 +47,7 @@ public final class TestUnaryPlusEval extends TestCase {
|
||||||
new NumberEval(37),
|
new NumberEval(37),
|
||||||
new NumberEval(38),
|
new NumberEval(38),
|
||||||
};
|
};
|
||||||
Eval[] args = {
|
ValueEval[] args = {
|
||||||
EvalFactory.createAreaEval(areaPtg, values),
|
EvalFactory.createAreaEval(areaPtg, values),
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -15,7 +15,6 @@
|
||||||
limitations under the License.
|
limitations under the License.
|
||||||
==================================================================== */
|
==================================================================== */
|
||||||
|
|
||||||
|
|
||||||
package org.apache.poi.hssf.record.formula.functions;
|
package org.apache.poi.hssf.record.formula.functions;
|
||||||
|
|
||||||
import junit.framework.AssertionFailedError;
|
import junit.framework.AssertionFailedError;
|
||||||
|
@ -24,6 +23,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.NumericValueEval;
|
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
|
||||||
import org.apache.poi.hssf.record.formula.eval.OperationEval;
|
import org.apache.poi.hssf.record.formula.eval.OperationEval;
|
||||||
|
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;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -53,7 +53,7 @@ public final class NumericFunctionInvoker {
|
||||||
* This method cannot be used for confirming error return codes. Any non-numeric evaluation
|
* This method cannot be used for confirming error return codes. Any non-numeric evaluation
|
||||||
* result causes the current junit test to fail.
|
* result causes the current junit test to fail.
|
||||||
*/
|
*/
|
||||||
public static double invoke(Function f, Eval[] args) {
|
public static double invoke(Function f, ValueEval[] args) {
|
||||||
try {
|
try {
|
||||||
return invokeInternal(f, args, -1, -1);
|
return invokeInternal(f, args, -1, -1);
|
||||||
} catch (NumericEvalEx e) {
|
} catch (NumericEvalEx e) {
|
||||||
|
@ -68,7 +68,7 @@ public final class NumericFunctionInvoker {
|
||||||
* This method cannot be used for confirming error return codes. Any non-numeric evaluation
|
* This method cannot be used for confirming error return codes. Any non-numeric evaluation
|
||||||
* result causes the current junit test to fail.
|
* result causes the current junit test to fail.
|
||||||
*/
|
*/
|
||||||
public static double invoke(OperationEval f, Eval[] args, int srcCellRow, int srcCellCol) {
|
public static double invoke(OperationEval f, ValueEval[] args, int srcCellRow, int srcCellCol) {
|
||||||
try {
|
try {
|
||||||
return invokeInternal(f, args, srcCellRow, srcCellCol);
|
return invokeInternal(f, args, srcCellRow, srcCellCol);
|
||||||
} catch (NumericEvalEx e) {
|
} catch (NumericEvalEx e) {
|
||||||
|
@ -80,7 +80,7 @@ public final class NumericFunctionInvoker {
|
||||||
/**
|
/**
|
||||||
* Formats nicer error messages for the junit output
|
* Formats nicer error messages for the junit output
|
||||||
*/
|
*/
|
||||||
private static double invokeInternal(Object target, Eval[] args, int srcCellRow, int srcCellCol)
|
private static double invokeInternal(Object target, ValueEval[] args, int srcCellRow, int srcCellCol)
|
||||||
throws NumericEvalEx {
|
throws NumericEvalEx {
|
||||||
Eval evalResult;
|
Eval evalResult;
|
||||||
// TODO - make OperationEval extend Function
|
// TODO - make OperationEval extend Function
|
||||||
|
@ -124,5 +124,4 @@ public final class NumericFunctionInvoker {
|
||||||
}
|
}
|
||||||
return a.getErrorCode() == b.getErrorCode();
|
return a.getErrorCode() == b.getErrorCode();
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
|
@ -25,7 +25,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.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;
|
||||||
|
@ -49,26 +48,26 @@ public final class TestCountFuncs extends TestCase {
|
||||||
|
|
||||||
public void testCountA() {
|
public void testCountA() {
|
||||||
|
|
||||||
Eval[] args;
|
ValueEval[] args;
|
||||||
|
|
||||||
args = new Eval[] {
|
args = new ValueEval[] {
|
||||||
new NumberEval(0),
|
new NumberEval(0),
|
||||||
};
|
};
|
||||||
confirmCountA(1, args);
|
confirmCountA(1, args);
|
||||||
|
|
||||||
args = new Eval[] {
|
args = new ValueEval[] {
|
||||||
new NumberEval(0),
|
new NumberEval(0),
|
||||||
new NumberEval(0),
|
new NumberEval(0),
|
||||||
new StringEval(""),
|
new StringEval(""),
|
||||||
};
|
};
|
||||||
confirmCountA(3, args);
|
confirmCountA(3, args);
|
||||||
|
|
||||||
args = new Eval[] {
|
args = new ValueEval[] {
|
||||||
EvalFactory.createAreaEval("D2:F5", new ValueEval[12]),
|
EvalFactory.createAreaEval("D2:F5", new ValueEval[12]),
|
||||||
};
|
};
|
||||||
confirmCountA(12, args);
|
confirmCountA(12, args);
|
||||||
|
|
||||||
args = new Eval[] {
|
args = new ValueEval[] {
|
||||||
EvalFactory.createAreaEval("D1:F5", new ValueEval[15]),
|
EvalFactory.createAreaEval("D1:F5", new ValueEval[15]),
|
||||||
EvalFactory.createRefEval("A1"),
|
EvalFactory.createRefEval("A1"),
|
||||||
EvalFactory.createAreaEval("A1:G6", new ValueEval[42]),
|
EvalFactory.createAreaEval("A1:G6", new ValueEval[42]),
|
||||||
|
@ -163,7 +162,6 @@ public final class TestCountFuncs extends TestCase {
|
||||||
|
|
||||||
range = EvalFactory.createAreaEval("A1:A5", values);
|
range = EvalFactory.createAreaEval("A1:A5", values);
|
||||||
confirmCountIf(4, range, new StringEval("<>111"));
|
confirmCountIf(4, range, new StringEval("<>111"));
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -182,24 +180,24 @@ public final class TestCountFuncs extends TestCase {
|
||||||
AreaEval arg0 = EvalFactory.createAreaEval("C1:C6", values);
|
AreaEval arg0 = EvalFactory.createAreaEval("C1:C6", values);
|
||||||
|
|
||||||
ValueEval criteriaArg = EvalFactory.createRefEval("A1", new NumberEval(25));
|
ValueEval criteriaArg = EvalFactory.createRefEval("A1", new NumberEval(25));
|
||||||
Eval[] args= { arg0, criteriaArg, };
|
ValueEval[] args= { arg0, criteriaArg, };
|
||||||
|
|
||||||
double actual = NumericFunctionInvoker.invoke(new Countif(), args);
|
double actual = NumericFunctionInvoker.invoke(new Countif(), args);
|
||||||
assertEquals(4, actual, 0D);
|
assertEquals(4, actual, 0D);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void confirmCountA(int expected, Eval[] args) {
|
private static void confirmCountA(int expected, ValueEval[] args) {
|
||||||
double result = NumericFunctionInvoker.invoke(new Counta(), args);
|
double result = NumericFunctionInvoker.invoke(new Counta(), args);
|
||||||
assertEquals(expected, result, 0);
|
assertEquals(expected, result, 0);
|
||||||
}
|
}
|
||||||
private static void confirmCountIf(int expected, AreaEval range, Eval criteria) {
|
private static void confirmCountIf(int expected, AreaEval range, ValueEval criteria) {
|
||||||
|
|
||||||
Eval[] args = { range, criteria, };
|
ValueEval[] args = { range, criteria, };
|
||||||
double result = NumericFunctionInvoker.invoke(new Countif(), args);
|
double result = NumericFunctionInvoker.invoke(new Countif(), args);
|
||||||
assertEquals(expected, result, 0);
|
assertEquals(expected, result, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static I_MatchPredicate createCriteriaPredicate(Eval ev) {
|
private static I_MatchPredicate createCriteriaPredicate(ValueEval ev) {
|
||||||
return Countif.createCriteriaPredicate(ev, 0, 0);
|
return Countif.createCriteriaPredicate(ev, 0, 0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -382,7 +380,7 @@ public final class TestCountFuncs extends TestCase {
|
||||||
assertEquals(expectedResult, matchPredicate.matches(new NumberEval(value)));
|
assertEquals(expectedResult, matchPredicate.matches(new NumberEval(value)));
|
||||||
}
|
}
|
||||||
private static void confirmPredicate(boolean expectedResult, I_MatchPredicate matchPredicate, String value) {
|
private static void confirmPredicate(boolean expectedResult, I_MatchPredicate matchPredicate, String value) {
|
||||||
Eval ev = value == null ? (Eval)BlankEval.INSTANCE : new StringEval(value);
|
ValueEval ev = value == null ? BlankEval.INSTANCE : new StringEval(value);
|
||||||
assertEquals(expectedResult, matchPredicate.matches(ev));
|
assertEquals(expectedResult, matchPredicate.matches(ev));
|
||||||
}
|
}
|
||||||
private static void confirmPredicate(boolean expectedResult, I_MatchPredicate matchPredicate, ErrorEval value) {
|
private static void confirmPredicate(boolean expectedResult, I_MatchPredicate matchPredicate, ErrorEval value) {
|
||||||
|
|
|
@ -21,7 +21,6 @@ import junit.framework.AssertionFailedError;
|
||||||
import junit.framework.TestCase;
|
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.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.eval.ValueEval;
|
||||||
|
@ -77,11 +76,11 @@ public final class TestIndex extends TestCase {
|
||||||
}
|
}
|
||||||
AreaEval arg0 = EvalFactory.createAreaEval(areaRefString, values);
|
AreaEval arg0 = EvalFactory.createAreaEval(areaRefString, values);
|
||||||
|
|
||||||
Eval[] args;
|
ValueEval[] args;
|
||||||
if (colNum > 0) {
|
if (colNum > 0) {
|
||||||
args = new Eval[] { arg0, new NumberEval(rowNum), new NumberEval(colNum), };
|
args = new ValueEval[] { arg0, new NumberEval(rowNum), new NumberEval(colNum), };
|
||||||
} else {
|
} else {
|
||||||
args = new Eval[] { arg0, new NumberEval(rowNum), };
|
args = new ValueEval[] { arg0, new NumberEval(rowNum), };
|
||||||
}
|
}
|
||||||
|
|
||||||
double actual = NumericFunctionInvoker.invoke(FUNC_INST, args);
|
double actual = NumericFunctionInvoker.invoke(FUNC_INST, args);
|
||||||
|
@ -99,10 +98,10 @@ public final class TestIndex extends TestCase {
|
||||||
new NumberEval(28.0),
|
new NumberEval(28.0),
|
||||||
};
|
};
|
||||||
AreaEval arg0 = EvalFactory.createAreaEval("A10:C10", values);
|
AreaEval arg0 = EvalFactory.createAreaEval("A10:C10", values);
|
||||||
Eval[] args = new Eval[] { arg0, MissingArgEval.instance, new NumberEval(2), };
|
ValueEval[] args = new ValueEval[] { arg0, MissingArgEval.instance, new NumberEval(2), };
|
||||||
Eval actualResult;
|
ValueEval actualResult;
|
||||||
try {
|
try {
|
||||||
actualResult = FUNC_INST.evaluate(args, 1, (short)1);
|
actualResult = (ValueEval) 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");
|
||||||
|
|
|
@ -19,7 +19,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.Eval;
|
|
||||||
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
import org.apache.poi.hssf.record.formula.eval.ValueEval;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -32,12 +31,12 @@ public final class TestRowCol extends TestCase {
|
||||||
public void testCol() {
|
public void testCol() {
|
||||||
Function target = new Column();
|
Function target = new Column();
|
||||||
{
|
{
|
||||||
Eval[] args = { EvalFactory.createRefEval("C5"), };
|
ValueEval[] args = { EvalFactory.createRefEval("C5"), };
|
||||||
double actual = NumericFunctionInvoker.invoke(target, args);
|
double actual = NumericFunctionInvoker.invoke(target, args);
|
||||||
assertEquals(3, actual, 0D);
|
assertEquals(3, actual, 0D);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Eval[] args = { EvalFactory.createAreaEval("E2:H12", new ValueEval[44]), };
|
ValueEval[] args = { EvalFactory.createAreaEval("E2:H12", new ValueEval[44]), };
|
||||||
double actual = NumericFunctionInvoker.invoke(target, args);
|
double actual = NumericFunctionInvoker.invoke(target, args);
|
||||||
assertEquals(5, actual, 0D);
|
assertEquals(5, actual, 0D);
|
||||||
}
|
}
|
||||||
|
@ -46,12 +45,12 @@ public final class TestRowCol extends TestCase {
|
||||||
public void testRow() {
|
public void testRow() {
|
||||||
Function target = new Row();
|
Function target = new Row();
|
||||||
{
|
{
|
||||||
Eval[] args = { EvalFactory.createRefEval("C5"), };
|
ValueEval[] args = { EvalFactory.createRefEval("C5"), };
|
||||||
double actual = NumericFunctionInvoker.invoke(target, args);
|
double actual = NumericFunctionInvoker.invoke(target, args);
|
||||||
assertEquals(5, actual, 0D);
|
assertEquals(5, actual, 0D);
|
||||||
}
|
}
|
||||||
{
|
{
|
||||||
Eval[] args = { EvalFactory.createAreaEval("E2:H12", new ValueEval[44]), };
|
ValueEval[] args = { EvalFactory.createAreaEval("E2:H12", new ValueEval[44]), };
|
||||||
double actual = NumericFunctionInvoker.invoke(target, args);
|
double actual = NumericFunctionInvoker.invoke(target, args);
|
||||||
assertEquals(2, actual, 0D);
|
assertEquals(2, actual, 0D);
|
||||||
}
|
}
|
||||||
|
@ -64,7 +63,7 @@ public final class TestRowCol extends TestCase {
|
||||||
confirmColumnsFunc("A1:B3", 2, 3);
|
confirmColumnsFunc("A1:B3", 2, 3);
|
||||||
confirmColumnsFunc("A1:A6", 1, 6);
|
confirmColumnsFunc("A1:A6", 1, 6);
|
||||||
|
|
||||||
Eval[] args = { EvalFactory.createRefEval("C5"), };
|
ValueEval[] args = { EvalFactory.createRefEval("C5"), };
|
||||||
double actual = NumericFunctionInvoker.invoke(new Columns(), args);
|
double actual = NumericFunctionInvoker.invoke(new Columns(), args);
|
||||||
assertEquals(1, actual, 0D);
|
assertEquals(1, actual, 0D);
|
||||||
}
|
}
|
||||||
|
@ -76,13 +75,13 @@ public final class TestRowCol extends TestCase {
|
||||||
confirmRowsFunc("A1:B3", 2, 3);
|
confirmRowsFunc("A1:B3", 2, 3);
|
||||||
confirmRowsFunc("A1:A6", 1, 6);
|
confirmRowsFunc("A1:A6", 1, 6);
|
||||||
|
|
||||||
Eval[] args = { EvalFactory.createRefEval("C5"), };
|
ValueEval[] args = { EvalFactory.createRefEval("C5"), };
|
||||||
double actual = NumericFunctionInvoker.invoke(new Rows(), args);
|
double actual = NumericFunctionInvoker.invoke(new Rows(), args);
|
||||||
assertEquals(1, actual, 0D);
|
assertEquals(1, actual, 0D);
|
||||||
}
|
}
|
||||||
|
|
||||||
private static void confirmRowsFunc(String areaRefStr, int nCols, int nRows) {
|
private static void confirmRowsFunc(String areaRefStr, int nCols, int nRows) {
|
||||||
Eval[] args = { EvalFactory.createAreaEval(areaRefStr, new ValueEval[nCols * nRows]), };
|
ValueEval[] args = { EvalFactory.createAreaEval(areaRefStr, new ValueEval[nCols * nRows]), };
|
||||||
|
|
||||||
double actual = NumericFunctionInvoker.invoke(new Rows(), args);
|
double actual = NumericFunctionInvoker.invoke(new Rows(), args);
|
||||||
assertEquals(nRows, actual, 0D);
|
assertEquals(nRows, actual, 0D);
|
||||||
|
@ -90,7 +89,7 @@ public final class TestRowCol extends TestCase {
|
||||||
|
|
||||||
|
|
||||||
private static void confirmColumnsFunc(String areaRefStr, int nCols, int nRows) {
|
private static void confirmColumnsFunc(String areaRefStr, int nCols, int nRows) {
|
||||||
Eval[] args = { EvalFactory.createAreaEval(areaRefStr, new ValueEval[nCols * nRows]), };
|
ValueEval[] args = { EvalFactory.createAreaEval(areaRefStr, new ValueEval[nCols * nRows]), };
|
||||||
|
|
||||||
double actual = NumericFunctionInvoker.invoke(new Columns(), args);
|
double actual = NumericFunctionInvoker.invoke(new Columns(), args);
|
||||||
assertEquals(nCols, actual, 0D);
|
assertEquals(nCols, actual, 0D);
|
||||||
|
|
Loading…
Reference in New Issue