(Should have been submitted with 693939) Fixing error value handling for numeric functions. Refactored hierarchy.

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@693947 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Josh Micich 2008-09-10 19:33:58 +00:00
parent 2dac9df840
commit 26b4b8b6a7
2 changed files with 64 additions and 2 deletions

View 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);
}
}

View 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);
}
}