]> source.dussan.org Git - poi.git/commitdiff
(Should have been submitted with 693939) Fixing error value handling for numeric...
authorJosh Micich <josh@apache.org>
Wed, 10 Sep 2008 19:33:58 +0000 (19:33 +0000)
committerJosh Micich <josh@apache.org>
Wed, 10 Sep 2008 19:33:58 +0000 (19:33 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@693947 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/record/formula/functions/FinanceFunction.java
src/java/org/apache/poi/hssf/record/formula/functions/MultiOperandNumericFunction.java

index c054c6dac4dcc5b6839eab4fc980b89015dc6809..a6956752be3c87d895bdd46e76b5f0ca9aeb5743 100644 (file)
@@ -17,6 +17,7 @@
 
 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.BoolEval;
 import org.apache.poi.hssf.record.formula.eval.ErrorEval;
 import org.apache.poi.hssf.record.formula.eval.Eval;
@@ -30,7 +31,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
  * Super class for all Evals for financial function evaluation.
  * 
  */
-public abstract class FinanceFunction extends NumericFunction {
+public abstract class FinanceFunction implements Function {
     private static final ValueEvalToNumericXlator DEFAULT_NUM_XLATOR =
         new ValueEvalToNumericXlator((short) (0
                 | ValueEvalToNumericXlator.BOOL_IS_PARSED  
@@ -68,4 +69,35 @@ public abstract class FinanceFunction extends NumericFunction {
         }
         return retval;
     }
+    
+    protected final ValueEval singleOperandEvaluate(Eval eval, int srcRow, short srcCol) {
+
+        if (eval instanceof AreaEval) {
+            AreaEval ae = (AreaEval) eval;
+            if (ae.contains(srcRow, srcCol)) { // circular ref!
+                return ErrorEval.CIRCULAR_REF_ERROR;
+            }
+            if (ae.isRow()) {
+                if (ae.isColumn()) {
+                       return ae.getRelativeValue(0, 0);
+                }
+                if (ae.containsColumn(srcCol)) {
+                    ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCol);
+                    ve = getXlator().attemptXlateToNumeric(ve);
+                    return getXlator().attemptXlateToNumeric(ve);
+                }
+                return ErrorEval.VALUE_INVALID;
+            }
+            if (ae.isColumn()) {
+                if (ae.containsRow(srcRow)) {
+                    ValueEval ve = ae.getValueAt(srcRow, ae.getFirstColumn());
+                    return getXlator().attemptXlateToNumeric(ve);
+                }
+                return ErrorEval.VALUE_INVALID;
+            }
+            return ErrorEval.VALUE_INVALID;
+        }
+        return getXlator().attemptXlateToNumeric((ValueEval) eval);
+    }
+    
 }
index a9e98ae313087f229d2b05da82d58b3b64ff84b8..7d07ddc1c13be5a6a3f16ccdf52a484c9941aeb3 100644 (file)
@@ -19,6 +19,7 @@ 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.BlankEval;
+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.NumericValueEval;
 import org.apache.poi.hssf.record.formula.eval.Ref2DEval;
@@ -32,7 +33,7 @@ import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
  * classes that take variable number of operands, and
  * where the order of operands does not matter
  */
-public abstract class MultiOperandNumericFunction extends NumericFunction {
+public abstract class MultiOperandNumericFunction implements Function {
     static final double[] EMPTY_DOUBLE_ARRAY = { };
     
     private static class DoubleList {
@@ -202,5 +203,34 @@ public abstract class MultiOperandNumericFunction extends NumericFunction {
     }
     
    
+    protected final ValueEval singleOperandEvaluate(Eval eval, int srcRow, short srcCol) {
+
+        if (eval instanceof AreaEval) {
+            AreaEval ae = (AreaEval) eval;
+            if (ae.contains(srcRow, srcCol)) { // circular ref!
+                return ErrorEval.CIRCULAR_REF_ERROR;
+            }
+            if (ae.isRow()) {
+                if (ae.isColumn()) {
+                       return ae.getRelativeValue(0, 0);
+                }
+                if (ae.containsColumn(srcCol)) {
+                    ValueEval ve = ae.getValueAt(ae.getFirstRow(), srcCol);
+                    ve = getXlator().attemptXlateToNumeric(ve);
+                    return getXlator().attemptXlateToNumeric(ve);
+                }
+                return ErrorEval.VALUE_INVALID;
+            }
+            if (ae.isColumn()) {
+                if (ae.containsRow(srcRow)) {
+                    ValueEval ve = ae.getValueAt(srcRow, ae.getFirstColumn());
+                    return getXlator().attemptXlateToNumeric(ve);
+                }
+                return ErrorEval.VALUE_INVALID;
+            }
+            return ErrorEval.VALUE_INVALID;
+        }
+        return getXlator().attemptXlateToNumeric((ValueEval) eval);
+    }
     
 }