]> source.dussan.org Git - poi.git/commitdiff
Bug 55195: use interface instead of implementation for
authorDominik Stadler <centic@apache.org>
Mon, 12 Aug 2013 20:27:08 +0000 (20:27 +0000)
committerDominik Stadler <centic@apache.org>
Mon, 12 Aug 2013 20:27:08 +0000 (20:27 +0000)
NumericValueEval and others.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1513247 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFFormulaEvaluator.java
src/java/org/apache/poi/ss/formula/functions/MultiOperandNumericFunction.java
src/testcases/org/apache/poi/hssf/usermodel/TestHSSFFormulaEvaluator.java

index d301c7388b92b4e357dfbf773a222ba25ab0faf5..06c1794775765dca550bf3c56a99c7e51fd2e740 100644 (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) {
index 6450c92940129ddcee79dc979f4a878020173903..9c89f69dbcf0b2f09405731e10a4c64e264c240f 100644 (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;
-                       temp.add(ne.getNumberValue());
+               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 instanceof NumericValueEval) {
+                       NumericValueEval ne = (NumericValueEval) ve;
+                       temp.add(ne.getNumberValue());
+                       return;
                }
-               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) {
index f28725669ce81955fa340b3d8bb68dfb245e7aa3..e34c1cdc54d94f495f5e7e71477678fb34049215 100644 (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++;
                }