You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by jo...@apache.org on 2008/09/10 21:34:06 UTC

svn commit: r693947 - in /poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions: FinanceFunction.java MultiOperandNumericFunction.java

Author: josh
Date: Wed Sep 10 12:33:58 2008
New Revision: 693947

URL: http://svn.apache.org/viewvc?rev=693947&view=rev
Log:
(Should have been submitted with 693939) Fixing error value handling for numeric functions. Refactored hierarchy.

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

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/FinanceFunction.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/FinanceFunction.java?rev=693947&r1=693946&r2=693947&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/FinanceFunction.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/FinanceFunction.java Wed Sep 10 12:33:58 2008
@@ -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 @@
  * 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 @@
         }
         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);
+    }
+    
 }

Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/MultiOperandNumericFunction.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/MultiOperandNumericFunction.java?rev=693947&r1=693946&r2=693947&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/MultiOperandNumericFunction.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/MultiOperandNumericFunction.java Wed Sep 10 12:33:58 2008
@@ -19,6 +19,7 @@
 
 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 @@
  * 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 @@
     }
     
    
+    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);
+    }
     
 }



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org