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/11 00:43:31 UTC
svn commit: r694050 - in /poi/trunk/src:
java/org/apache/poi/hssf/record/formula/eval/
java/org/apache/poi/hssf/record/formula/functions/
testcases/org/apache/poi/hssf/data/
testcases/org/apache/poi/hssf/record/formula/functions/
Author: josh
Date: Wed Sep 10 15:43:30 2008
New Revision: 694050
URL: http://svn.apache.org/viewvc?rev=694050&view=rev
Log:
Refactored finance functions.
Removed:
poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Fv.java
poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Nper.java
poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Pmt.java
poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Pv.java
Modified:
poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/FunctionEval.java
poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/ValueEvalToNumericXlator.java
poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/AggregateFunction.java
poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/FinanceFunction.java
poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Maxa.java
poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Mina.java
poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Mode.java
poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/MultiOperandNumericFunction.java
poi/trunk/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls
poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestPmt.java
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/FunctionEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/FunctionEval.java?rev=694050&r1=694049&r2=694050&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/FunctionEval.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/FunctionEval.java Wed Sep 10 15:43:30 2008
@@ -129,10 +129,10 @@
retval[52] = new Growth(); // GROWTH
retval[53] = new Goto(); // GOTO
retval[54] = new Halt(); // HALT
- retval[56] = new Pv(); // PV
- retval[57] = new Fv(); // FV
- retval[58] = new Nper(); // NPER
- retval[59] = new Pmt(); // PMT
+ retval[56] = FinanceFunction.PV;
+ retval[57] = FinanceFunction.FV;
+ retval[58] = FinanceFunction.NPER;
+ retval[59] = FinanceFunction.PMT;
retval[60] = new Rate(); // RATE
retval[61] = new Mirr(); // MIRR
retval[62] = new Irr(); // IRR
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/ValueEvalToNumericXlator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/ValueEvalToNumericXlator.java?rev=694050&r1=694049&r2=694050&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/ValueEvalToNumericXlator.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/eval/ValueEvalToNumericXlator.java Wed Sep 10 15:43:30 2008
@@ -1,23 +1,20 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
-/*
- * Created on May 14, 2005
- *
- */
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
+
package org.apache.poi.hssf.record.formula.eval;
/**
@@ -30,11 +27,7 @@
public static final int BOOL_IS_PARSED = 0x0002;
public static final int BLANK_IS_PARSED = 0x0004; // => blanks are not ignored, converted to 0
- public static final int REF_STRING_IS_PARSED = 0x0008;
- public static final int REF_BOOL_IS_PARSED = 0x0010;
- public static final int REF_BLANK_IS_PARSED = 0x0020;
-
- public static final int STRING_IS_INVALID_VALUE = 0x0800;
+ public static final int REF_BOOL_IS_PARSED = 0x0008;
private final int flags;
@@ -68,11 +61,11 @@
if (eval instanceof BoolEval) {
return ((flags & BOOL_IS_PARSED) > 0)
? (NumericValueEval) eval
- : xlateBlankEval(BLANK_IS_PARSED);
+ : xlateBlankEval();
}
if (eval instanceof StringEval) {
- return xlateStringEval((StringEval) eval); // TODO: recursive call needed
+ return xlateStringEval((StringEval) eval);
}
if (eval instanceof RefEval) {
@@ -84,7 +77,7 @@
}
if (eval instanceof BlankEval) {
- return xlateBlankEval(BLANK_IS_PARSED);
+ return xlateBlankEval();
}
// probably AreaEval? then not acceptable.
@@ -97,8 +90,8 @@
* valued numbereval is returned, else BlankEval.INSTANCE
* is returned.
*/
- private ValueEval xlateBlankEval(int flag) {
- return ((flags & flag) > 0)
+ private ValueEval xlateBlankEval() {
+ return ((flags & BLANK_IS_PARSED) > 0)
? (ValueEval) NumberEval.ZERO
: BlankEval.INSTANCE;
}
@@ -122,7 +115,8 @@
}
if (eval instanceof StringEval) {
- return xlateRefStringEval((StringEval) eval);
+ // all ref strings are blanks
+ return BlankEval.INSTANCE;
}
if (eval instanceof ErrorEval) {
@@ -130,7 +124,7 @@
}
if (eval instanceof BlankEval) {
- return xlateBlankEval(REF_BLANK_IS_PARSED);
+ return xlateBlankEval();
}
throw new RuntimeException("Invalid ValueEval type passed for conversion: ("
@@ -151,29 +145,7 @@
}
return new NumberEval(d.doubleValue());
}
- // strings are errors?
- if ((flags & STRING_IS_INVALID_VALUE) > 0) {
- return ErrorEval.VALUE_INVALID;
- }
-
- // ignore strings
- return xlateBlankEval(BLANK_IS_PARSED);
- }
-
- /**
- * uses the relevant flags to decode the StringEval
- * @param eval
- */
- private ValueEval xlateRefStringEval(StringEval sve) {
- if ((flags & REF_STRING_IS_PARSED) > 0) {
- String s = sve.getStringValue();
- Double d = OperandResolver.parseDouble(s);
- if(d == null) {
- return ErrorEval.VALUE_INVALID;
- }
- return new NumberEval(d.doubleValue());
- }
- // strings are blanks
- return BlankEval.INSTANCE;
+ // else strings are errors?
+ return ErrorEval.VALUE_INVALID;
}
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/AggregateFunction.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/AggregateFunction.java?rev=694050&r1=694049&r2=694050&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/AggregateFunction.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/AggregateFunction.java Wed Sep 10 15:43:30 2008
@@ -19,6 +19,7 @@
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
/**
@@ -32,8 +33,8 @@
| ValueEvalToNumericXlator.STRING_IS_PARSED
));
- protected final ValueEvalToNumericXlator getXlator() {
- return DEFAULT_NUM_XLATOR;
+ protected ValueEval attemptXlateToNumeric(ValueEval ve) {
+ return DEFAULT_NUM_XLATOR.attemptXlateToNumeric(ve);
}
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=694050&r1=694049&r2=694050&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 15:43:30 2008
@@ -1,103 +1,77 @@
-/*
-* Licensed to the Apache Software Foundation (ASF) under one or more
-* contributor license agreements. See the NOTICE file distributed with
-* this work for additional information regarding copyright ownership.
-* The ASF licenses this file to You under the Apache License, Version 2.0
-* (the "License"); you may not use this file except in compliance with
-* the License. You may obtain a copy of the License at
-*
-* http://www.apache.org/licenses/LICENSE-2.0
-*
-* Unless required by applicable law or agreed to in writing, software
-* distributed under the License is distributed on an "AS IS" BASIS,
-* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
-* See the License for the specific language governing permissions and
-* limitations under the License.
-*/
+/* ====================================================================
+ Licensed to the Apache Software Foundation (ASF) under one or more
+ contributor license agreements. See the NOTICE file distributed with
+ this work for additional information regarding copyright ownership.
+ The ASF licenses this file to You under the Apache License, Version 2.0
+ (the "License"); you may not use this file except in compliance with
+ the License. You may obtain a copy of the License at
-package org.apache.poi.hssf.record.formula.functions;
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing, software
+ distributed under the License is distributed on an "AS IS" BASIS,
+ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ See the License for the specific language governing permissions and
+ limitations under the License.
+==================================================================== */
-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;
-import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
-import org.apache.poi.hssf.record.formula.eval.ValueEval;
-import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
+package org.apache.poi.hssf.record.formula.functions;
+import org.apache.poi.hssf.record.formula.eval.EvaluationException;
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
* Super class for all Evals for financial function evaluation.
- *
+ *
*/
-public abstract class FinanceFunction implements Function {
- private static final ValueEvalToNumericXlator DEFAULT_NUM_XLATOR =
- new ValueEvalToNumericXlator((short) (0
- | ValueEvalToNumericXlator.BOOL_IS_PARSED
- | ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.STRING_IS_PARSED
- | ValueEvalToNumericXlator.REF_STRING_IS_PARSED
- | ValueEvalToNumericXlator.BLANK_IS_PARSED
- | ValueEvalToNumericXlator.REF_BLANK_IS_PARSED
- //| ValueEvalToNumericXlator.REF_STRING_TO_BOOL_IS_PARSED
- //| ValueEvalToNumericXlator.STRING_IS_INVALID_VALUE
- //| ValueEvalToNumericXlator.REF_STRING_IS_INVALID_VALUE
- ));
-
- /**
- * this is the default impl of the factory(ish) method getXlator.
- * Subclasses can override this method
- * if they desire to return a different ValueEvalToNumericXlator instance
- * than the default.
- */
- protected final ValueEvalToNumericXlator getXlator() {
- return DEFAULT_NUM_XLATOR;
- }
-
- protected final ValueEval singleOperandNumericAsBoolean(Eval eval, int srcRow, short srcCol) {
- ValueEval retval = null;
- retval = singleOperandEvaluate(eval, srcRow, srcCol);
- if (retval instanceof NumericValueEval) {
- NumericValueEval nve = (NumericValueEval) retval;
- retval = (nve.getNumberValue() == 0)
- ? BoolEval.FALSE
- : BoolEval.TRUE;
- }
- else {
- retval = ErrorEval.VALUE_INVALID;
- }
- 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);
- }
-
+public abstract class FinanceFunction extends NumericFunction.MultiArg {
+
+ protected FinanceFunction() {
+ super (3, 5);
+ }
+
+ protected double evaluate(double[] ds) throws EvaluationException {
+ // All finance functions have 3 to 5 args, first 4 are numbers, last is boolean
+ // default for last 2 args are 0.0 and false
+ // Text boolean literals are not valid for the last arg
+
+ double arg3 = 0.0;
+ double arg4 = 0.0;
+
+ switch(ds.length) {
+ case 5:
+ arg4 = ds[4];
+ case 4:
+ arg3 = ds[3];
+ case 3:
+ break;
+ default:
+ throw new IllegalStateException("Wrong number of arguments");
+ }
+ return evaluate(ds[0], ds[1], ds[2], arg3, arg4!=0.0);
+ }
+
+ protected abstract double evaluate(double rate, double arg1, double arg2, double arg3, boolean type) throws EvaluationException ;
+
+
+ public static final Function FV = new FinanceFunction() {
+ protected double evaluate(double rate, double arg1, double arg2, double arg3, boolean type) {
+ return FinanceLib.fv(rate, arg1, arg2, arg3, type);
+ }
+ };
+ public static final Function NPER = new FinanceFunction() {
+ protected double evaluate(double rate, double arg1, double arg2, double arg3, boolean type) {
+ return FinanceLib.nper(rate, arg1, arg2, arg3, type);
+ }
+ };
+ public static final Function PMT = new FinanceFunction() {
+ protected double evaluate(double rate, double arg1, double arg2, double arg3, boolean type) {
+ return FinanceLib.pmt(rate, arg1, arg2, arg3, type);
+ }
+ };
+ public static final Function PV = new FinanceFunction() {
+ protected double evaluate(double rate, double arg1, double arg2, double arg3, boolean type) {
+ return FinanceLib.pv(rate, arg1, arg2, arg3, type);
+ }
+ };
}
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Maxa.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Maxa.java?rev=694050&r1=694049&r2=694050&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Maxa.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Maxa.java Wed Sep 10 15:43:30 2008
@@ -17,6 +17,7 @@
package org.apache.poi.hssf.record.formula.functions;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
/**
@@ -29,19 +30,12 @@
ValueEvalToNumericXlator.BOOL_IS_PARSED
| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
| ValueEvalToNumericXlator.STRING_IS_PARSED
- //| ValueEvalToNumericXlator.REF_STRING_IS_PARSED
- //| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
- //| ValueEvalToNumericXlator.STRING_TO_BOOL_IS_PARSED
- //| ValueEvalToNumericXlator.REF_STRING_TO_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.STRING_IS_INVALID_VALUE
- //| ValueEvalToNumericXlator.REF_STRING_IS_INVALID_VALUE
| ValueEvalToNumericXlator.BLANK_IS_PARSED
- | ValueEvalToNumericXlator.REF_BLANK_IS_PARSED
));
- protected ValueEvalToNumericXlator getXlator() {
- return DEFAULT_NUM_XLATOR;
- }
+ protected ValueEval attemptXlateToNumeric(ValueEval ve) {
+ return DEFAULT_NUM_XLATOR.attemptXlateToNumeric(ve);
+ }
public double evaluate(double[] values) {
return values.length > 0 ? MathX.max(values) : 0;
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Mina.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Mina.java?rev=694050&r1=694049&r2=694050&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Mina.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Mina.java Wed Sep 10 15:43:30 2008
@@ -17,31 +17,25 @@
package org.apache.poi.hssf.record.formula.functions;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
*
*/
-public class Mina extends MultiOperandNumericFunction {
+public final class Mina extends MultiOperandNumericFunction {
private static final ValueEvalToNumericXlator DEFAULT_NUM_XLATOR =
new ValueEvalToNumericXlator((short) (
ValueEvalToNumericXlator.BOOL_IS_PARSED
| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
| ValueEvalToNumericXlator.STRING_IS_PARSED
- //| ValueEvalToNumericXlator.REF_STRING_IS_PARSED
- //| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
- //| ValueEvalToNumericXlator.STRING_TO_BOOL_IS_PARSED
- //| ValueEvalToNumericXlator.REF_STRING_TO_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.STRING_IS_INVALID_VALUE
- //| ValueEvalToNumericXlator.REF_STRING_IS_INVALID_VALUE
- | ValueEvalToNumericXlator.REF_BLANK_IS_PARSED
| ValueEvalToNumericXlator.BLANK_IS_PARSED
));
- protected ValueEvalToNumericXlator getXlator() {
- return DEFAULT_NUM_XLATOR;
- }
+ protected ValueEval attemptXlateToNumeric(ValueEval ve) {
+ return DEFAULT_NUM_XLATOR.attemptXlateToNumeric(ve);
+ }
public double evaluate(double[] values) {
return values.length > 0 ? MathX.min(values) : 0;
Modified: poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Mode.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Mode.java?rev=694050&r1=694049&r2=694050&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Mode.java (original)
+++ poi/trunk/src/java/org/apache/poi/hssf/record/formula/functions/Mode.java Wed Sep 10 15:43:30 2008
@@ -19,6 +19,7 @@
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
/**
@@ -26,39 +27,25 @@
*
*/
public class Mode extends MultiOperandNumericFunction {
- private static final ValueEvalToNumericXlator DEFAULT_NUM_XLATOR =
- new ValueEvalToNumericXlator((short) (0
- //| ValueEvalToNumericXlator.BOOL_IS_PARSED
- //| ValueEvalToNumericXlator.REF_BOOL_IS_PARSED
- //| ValueEvalToNumericXlator.EVALUATED_REF_BOOL_IS_PARSED
- //| ValueEvalToNumericXlator.STRING_IS_PARSED
- //| ValueEvalToNumericXlator.REF_STRING_IS_PARSED
- //| ValueEvalToNumericXlator.EVALUATED_REF_STRING_IS_PARSED
- //| ValueEvalToNumericXlator.STRING_TO_BOOL_IS_PARSED
- //| ValueEvalToNumericXlator.REF_STRING_TO_BOOL_IS_PARSED
- | ValueEvalToNumericXlator.STRING_IS_INVALID_VALUE
- //| ValueEvalToNumericXlator.REF_STRING_IS_INVALID_VALUE
- //| ValueEvalToNumericXlator.EVALUATED_REF_BLANK_IS_PARSED
- //| ValueEvalToNumericXlator.REF_BLANK_IS_PARSED
- //| ValueEvalToNumericXlator.BLANK_IS_PARSED
- ));
-
- /**
- * this is the default impl for the factory method getXlator
- * of the super class NumericFunction. Subclasses can override this method
- * if they desire to return a different ValueEvalToNumericXlator instance
- * than the default.
- */
- protected ValueEvalToNumericXlator getXlator() {
- return DEFAULT_NUM_XLATOR;
- }
+ private static final ValueEvalToNumericXlator DEFAULT_NUM_XLATOR =
+ new ValueEvalToNumericXlator(0);
- protected double evaluate(double[] values) throws EvaluationException {
- double d = StatsLib.mode(values);
- if (Double.isNaN(d)) {
- // TODO - StatsLib is returning NaN to denote 'no duplicate values'
- throw new EvaluationException(ErrorEval.NA);
- }
- return d;
- }
+ /**
+ * this is the default impl for the factory method getXlator
+ * of the super class NumericFunction. Subclasses can override this method
+ * if they desire to return a different ValueEvalToNumericXlator instance
+ * than the default.
+ */
+ protected ValueEval attemptXlateToNumeric(ValueEval ve) {
+ return DEFAULT_NUM_XLATOR.attemptXlateToNumeric(ve);
+ }
+
+ protected double evaluate(double[] values) throws EvaluationException {
+ double d = StatsLib.mode(values);
+ if (Double.isNaN(d)) {
+ // TODO - StatsLib is returning NaN to denote 'no duplicate values'
+ throw new EvaluationException(ErrorEval.NA);
+ }
+ return d;
+ }
}
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=694050&r1=694049&r2=694050&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 15:43:30 2008
@@ -27,7 +27,6 @@
import org.apache.poi.hssf.record.formula.eval.Ref2DEval;
import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
-import org.apache.poi.hssf.record.formula.eval.ValueEvalToNumericXlator;
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
@@ -74,9 +73,6 @@
private static final int DEFAULT_MAX_NUM_OPERANDS = 30;
- protected abstract ValueEvalToNumericXlator getXlator();
-
-
public final Eval evaluate(Eval[] args, int srcCellRow, short srcCellCol) {
double d;
@@ -185,7 +181,5 @@
}
- protected ValueEval attemptXlateToNumeric(ValueEval ve) {
- return getXlator().attemptXlateToNumeric(ve);
- }
+ protected abstract ValueEval attemptXlateToNumeric(ValueEval ve);
}
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/data/FormulaEvalTestData.xls?rev=694050&r1=694049&r2=694050&view=diff
==============================================================================
Binary files - no diff available.
Modified: poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestPmt.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestPmt.java?rev=694050&r1=694049&r2=694050&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestPmt.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/record/formula/functions/TestPmt.java Wed Sep 10 15:43:30 2008
@@ -36,7 +36,7 @@
assertEquals(expected, ne.getNumberValue(), 0.00005);
}
private static Eval invoke(Eval[] args) {
- return new Pmt().evaluate(args, -1, (short)-1);
+ return FinanceFunction.PMT.evaluate(args, -1, (short)-1);
}
/**
* Invocation when not expecting an error result
---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org