Bug 55195: use interface instead of implementation for

NumericValueEval and others.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1513247 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Dominik Stadler 2013-08-12 20:27:08 +00:00
parent 0124294b3f
commit 5ce961a826
3 changed files with 26 additions and 23 deletions

View File

@ -22,8 +22,8 @@ import org.apache.poi.ss.formula.IStabilityClassifier;
import org.apache.poi.ss.formula.WorkbookEvaluator;
import org.apache.poi.ss.formula.eval.BoolEval;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.NumericValueEval;
import org.apache.poi.ss.formula.eval.StringValueEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.Cell;
@ -348,20 +348,20 @@ public class HSSFFormulaEvaluator implements FormulaEvaluator {
/**
* Returns a CellValue wrapper around the supplied ValueEval instance.
* @param eval
* @param cell
*/
private CellValue evaluateFormulaCellValue(Cell cell) {
ValueEval eval = _bookEvaluator.evaluate(new HSSFEvaluationCell((HSSFCell)cell));
if (eval instanceof NumberEval) {
NumberEval ne = (NumberEval) eval;
return new CellValue(ne.getNumberValue());
}
if (eval instanceof BoolEval) {
BoolEval be = (BoolEval) eval;
return CellValue.valueOf(be.getBooleanValue());
}
if (eval instanceof StringEval) {
StringEval ne = (StringEval) eval;
if (eval instanceof NumericValueEval) {
NumericValueEval ne = (NumericValueEval) eval;
return new CellValue(ne.getNumberValue());
}
if (eval instanceof StringValueEval) {
StringValueEval ne = (StringValueEval) eval;
return new CellValue(ne.getStringValue());
}
if (eval instanceof ErrorEval) {

View File

@ -22,9 +22,10 @@ import org.apache.poi.ss.formula.eval.BoolEval;
import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.NumberEval;
import org.apache.poi.ss.formula.eval.NumericValueEval;
import org.apache.poi.ss.formula.eval.OperandResolver;
import org.apache.poi.ss.formula.eval.RefEval;
import org.apache.poi.ss.formula.eval.StringEval;
import org.apache.poi.ss.formula.eval.StringValueEval;
import org.apache.poi.ss.formula.eval.ValueEval;
import org.apache.poi.ss.formula.TwoDEval;
@ -165,20 +166,24 @@ public abstract class MultiOperandNumericFunction implements Function {
if (ve == null) {
throw new IllegalArgumentException("ve must not be null");
}
if (ve instanceof NumberEval) {
NumberEval ne = (NumberEval) ve;
if (ve instanceof BoolEval) {
if (!isViaReference || _isReferenceBoolCounted) {
BoolEval boolEval = (BoolEval) ve;
temp.add(boolEval.getNumberValue());
}
return;
}
if (ve instanceof NumericValueEval) {
NumericValueEval ne = (NumericValueEval) ve;
temp.add(ne.getNumberValue());
return;
}
if (ve instanceof ErrorEval) {
throw new EvaluationException((ErrorEval) ve);
}
if (ve instanceof StringEval) {
if (ve instanceof StringValueEval) {
if (isViaReference) {
// ignore all ref strings
return;
}
String s = ((StringEval) ve).getStringValue();
String s = ((StringValueEval) ve).getStringValue();
Double d = OperandResolver.parseDouble(s);
if(d == null) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
@ -186,12 +191,8 @@ public abstract class MultiOperandNumericFunction implements Function {
temp.add(d.doubleValue());
return;
}
if (ve instanceof BoolEval) {
if (!isViaReference || _isReferenceBoolCounted) {
BoolEval boolEval = (BoolEval) ve;
temp.add(boolEval.getNumberValue());
}
return;
if (ve instanceof ErrorEval) {
throw new EvaluationException((ErrorEval) ve);
}
if (ve == BlankEval.instance) {
if (_isBlankCounted) {

View File

@ -59,6 +59,7 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
/**
* Test for bug due to attempt to convert a cached formula error result to a boolean
*/
@Override
public void testUpdateCachedFormulaResultFromErrorToNumber_bug46479() {
HSSFWorkbook wb = new HSSFWorkbook();
@ -132,6 +133,7 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
public EvalCountListener() {
_evalCount = 0;
}
@Override
public void onStartEvaluate(EvaluationCell cell, ICacheEntry entry) {
_evalCount++;
}