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.WorkbookEvaluator;
import org.apache.poi.ss.formula.eval.BoolEval; import org.apache.poi.ss.formula.eval.BoolEval;
import org.apache.poi.ss.formula.eval.ErrorEval; import org.apache.poi.ss.formula.eval.ErrorEval;
import org.apache.poi.ss.formula.eval.NumberEval; import org.apache.poi.ss.formula.eval.NumericValueEval;
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.eval.ValueEval;
import org.apache.poi.ss.formula.udf.UDFFinder; import org.apache.poi.ss.formula.udf.UDFFinder;
import org.apache.poi.ss.usermodel.Cell; 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. * Returns a CellValue wrapper around the supplied ValueEval instance.
* @param eval * @param cell
*/ */
private CellValue evaluateFormulaCellValue(Cell cell) { private CellValue evaluateFormulaCellValue(Cell cell) {
ValueEval eval = _bookEvaluator.evaluate(new HSSFEvaluationCell((HSSFCell)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) { if (eval instanceof BoolEval) {
BoolEval be = (BoolEval) eval; BoolEval be = (BoolEval) eval;
return CellValue.valueOf(be.getBooleanValue()); return CellValue.valueOf(be.getBooleanValue());
} }
if (eval instanceof StringEval) { if (eval instanceof NumericValueEval) {
StringEval ne = (StringEval) eval; NumericValueEval ne = (NumericValueEval) eval;
return new CellValue(ne.getNumberValue());
}
if (eval instanceof StringValueEval) {
StringValueEval ne = (StringValueEval) eval;
return new CellValue(ne.getStringValue()); return new CellValue(ne.getStringValue());
} }
if (eval instanceof ErrorEval) { 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.ErrorEval;
import org.apache.poi.ss.formula.eval.EvaluationException; import org.apache.poi.ss.formula.eval.EvaluationException;
import org.apache.poi.ss.formula.eval.NumberEval; 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.OperandResolver;
import org.apache.poi.ss.formula.eval.RefEval; 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.eval.ValueEval;
import org.apache.poi.ss.formula.TwoDEval; import org.apache.poi.ss.formula.TwoDEval;
@ -165,20 +166,24 @@ public abstract class MultiOperandNumericFunction implements Function {
if (ve == null) { if (ve == null) {
throw new IllegalArgumentException("ve must not be null"); throw new IllegalArgumentException("ve must not be null");
} }
if (ve instanceof NumberEval) { if (ve instanceof BoolEval) {
NumberEval ne = (NumberEval) ve; if (!isViaReference || _isReferenceBoolCounted) {
BoolEval boolEval = (BoolEval) ve;
temp.add(boolEval.getNumberValue());
}
return;
}
if (ve instanceof NumericValueEval) {
NumericValueEval ne = (NumericValueEval) ve;
temp.add(ne.getNumberValue()); temp.add(ne.getNumberValue());
return; return;
} }
if (ve instanceof ErrorEval) { if (ve instanceof StringValueEval) {
throw new EvaluationException((ErrorEval) ve);
}
if (ve instanceof StringEval) {
if (isViaReference) { if (isViaReference) {
// ignore all ref strings // ignore all ref strings
return; return;
} }
String s = ((StringEval) ve).getStringValue(); String s = ((StringValueEval) ve).getStringValue();
Double d = OperandResolver.parseDouble(s); Double d = OperandResolver.parseDouble(s);
if(d == null) { if(d == null) {
throw new EvaluationException(ErrorEval.VALUE_INVALID); throw new EvaluationException(ErrorEval.VALUE_INVALID);
@ -186,12 +191,8 @@ public abstract class MultiOperandNumericFunction implements Function {
temp.add(d.doubleValue()); temp.add(d.doubleValue());
return; return;
} }
if (ve instanceof BoolEval) { if (ve instanceof ErrorEval) {
if (!isViaReference || _isReferenceBoolCounted) { throw new EvaluationException((ErrorEval) ve);
BoolEval boolEval = (BoolEval) ve;
temp.add(boolEval.getNumberValue());
}
return;
} }
if (ve == BlankEval.instance) { if (ve == BlankEval.instance) {
if (_isBlankCounted) { 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 * Test for bug due to attempt to convert a cached formula error result to a boolean
*/ */
@Override
public void testUpdateCachedFormulaResultFromErrorToNumber_bug46479() { public void testUpdateCachedFormulaResultFromErrorToNumber_bug46479() {
HSSFWorkbook wb = new HSSFWorkbook(); HSSFWorkbook wb = new HSSFWorkbook();
@ -132,6 +133,7 @@ public final class TestHSSFFormulaEvaluator extends BaseTestFormulaEvaluator {
public EvalCountListener() { public EvalCountListener() {
_evalCount = 0; _evalCount = 0;
} }
@Override
public void onStartEvaluate(EvaluationCell cell, ICacheEntry entry) { public void onStartEvaluate(EvaluationCell cell, ICacheEntry entry) {
_evalCount++; _evalCount++;
} }