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.ValueEval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
return BoolEval.valueOf(val == _desiredParity);
}
- private static int evaluateArgParity(Eval arg, int srcCellRow, int srcCellCol) throws EvaluationException {
+ private static int evaluateArgParity(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException {
ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, (short)srcCellCol);
double d = OperandResolver.coerceValueToDouble(ve);
import java.util.regex.Pattern;
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.ValueEval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
return new NumberEval(result);
}
- private static double evaluateDateArg(Eval arg, int srcCellRow, int srcCellCol) throws EvaluationException {
+ private static double evaluateDateArg(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException {
ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, (short) srcCellCol);
if (ve instanceof StringEval) {
return cal;
}
- private static int evaluateIntArg(Eval arg, int srcCellRow, int srcCellCol) throws EvaluationException {
+ private static int evaluateIntArg(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException {
ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, (short) srcCellCol);
return OperandResolver.coerceValueToInt(ve);
}
+++ /dev/null
-/*
-* 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 8, 2005
- *
- */
-package org.apache.poi.hssf.record.formula.eval;
-
-/**
- * @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- *
- */
-public interface Eval {
- // TODO - remove this interface
-}
/**
* Provides functionality for evaluating arguments to functions and operators.
- *
+ *
* @author Josh Micich
*/
public final class OperandResolver {
* @return a <tt>NumberEval</tt>, <tt>StringEval</tt>, <tt>BoolEval</tt> or <tt>BlankEval</tt>.
* Never <code>null</code> or <tt>ErrorEval</tt>.
* @throws EvaluationException(#VALUE!) if srcCellRow or srcCellCol do not properly index into
- * an AreaEval. If the actual value retrieved is an ErrorEval, a corresponding
+ * an AreaEval. If the actual value retrieved is an ErrorEval, a corresponding
* EvaluationException is thrown.
*/
- public static ValueEval getSingleValue(Eval arg, int srcCellRow, short srcCellCol)
+ public static ValueEval getSingleValue(ValueEval arg, int srcCellRow, short srcCellCol)
throws EvaluationException {
- Eval result;
+ ValueEval result;
if (arg instanceof RefEval) {
result = ((RefEval) arg).getInnerValueEval();
} else if (arg instanceof AreaEval) {
* Implements (some perhaps not well known) Excel functionality to select a single cell from an
* area depending on the coordinates of the calling cell. Here is an example demonstrating
* both selection from a single row area and a single column area in the same formula.
- *
+ *
* <table border="1" cellpadding="1" cellspacing="1" summary="sample spreadsheet">
* <tr><th> </th><th> A </th><th> B </th><th> C </th><th> D </th></tr>
* <tr><th>1</th><td>15</td><td>20</td><td>25</td><td> </td></tr>
* <tr><th>3</th><td> </td><td> </td><td> </td><td>300</td></tr>
* <tr><th>3</th><td> </td><td> </td><td> </td><td>400</td></tr>
* </table>
- *
+ *
* If the formula "=1000+A1:B1+D2:D3" is put into the 9 cells from A2 to C4, the spreadsheet
* will look like this:
- *
+ *
* <table border="1" cellpadding="1" cellspacing="1" summary="sample spreadsheet">
* <tr><th> </th><th> A </th><th> B </th><th> C </th><th> D </th></tr>
* <tr><th>1</th><td>15</td><td>20</td><td>25</td><td> </td></tr>
* <tr><th>3</th><td>1315</td><td>1320</td><td>#VALUE!</td><td>300</td></tr>
* <tr><th>4</th><td>#VALUE!</td><td>#VALUE!</td><td>#VALUE!</td><td>400</td></tr>
* </table>
- *
- * Note that the row area (A1:B1) does not include column C and the column area (D2:D3) does
+ *
+ * Note that the row area (A1:B1) does not include column C and the column area (D2:D3) does
* not include row 4, so the values in C1(=25) and D4(=400) are not accessible to the formula
* as written, but in the 4 cells A2:B3, the row and column selection works ok.<p/>
- *
- * The same concept is extended to references across sheets, such that even multi-row,
+ *
+ * The same concept is extended to references across sheets, such that even multi-row,
* multi-column areas can be useful.<p/>
- *
+ *
* Of course with carefully (or carelessly) chosen parameters, cyclic references can occur and
- * hence this method <b>can</b> throw a 'circular reference' EvaluationException. Note that
+ * hence this method <b>can</b> throw a 'circular reference' EvaluationException. Note that
* this method does not attempt to detect cycles. Every cell in the specified Area <tt>ae</tt>
- * has already been evaluated prior to this method call. Any cell (or cell<b>s</b>) part of
- * <tt>ae</tt> that would incur a cyclic reference error if selected by this method, will
+ * has already been evaluated prior to this method call. Any cell (or cell<b>s</b>) part of
+ * <tt>ae</tt> that would incur a cyclic reference error if selected by this method, will
* already have the value <t>ErrorEval.CIRCULAR_REF_ERROR</tt> upon entry to this method. It
* is assumed logic exists elsewhere to produce this behaviour.
- *
+ *
* @return whatever the selected cell's evaluated value is. Never <code>null</code>. Never
* <tt>ErrorEval</tt>.
* @throws EvaluationException if there is a problem with indexing into the area, or if the
* evaluated cell has an error.
*/
- public static ValueEval chooseSingleElementFromArea(AreaEval ae,
+ public static ValueEval chooseSingleElementFromArea(AreaEval ae,
int srcCellRow, short srcCellCol) throws EvaluationException {
ValueEval result = chooseSingleElementFromAreaInternal(ae, srcCellRow, srcCellCol);
if(result == null) {
}
/**
- * @return possibly <tt>ErrorEval</tt>, and <code>null</code>
+ * @return possibly <tt>ErrorEval</tt>, and <code>null</code>
*/
- private static ValueEval chooseSingleElementFromAreaInternal(AreaEval ae,
+ private static ValueEval chooseSingleElementFromAreaInternal(AreaEval ae,
int srcCellRow, short srcCellCol) throws EvaluationException {
if(false) {
Another reason there's little value in attempting to detect circular references here is
that only direct circular references could be detected. If the cycle involved two or more
- cells this method could not detect it.
+ cells this method could not detect it.
Logic to detect evaluation cycles of all kinds has been coded in EvaluationCycleDetector
- (and HSSFFormulaEvaluator).
+ (and HSSFFormulaEvaluator).
*/
}
/**
* Applies some conversion rules if the supplied value is not already an integer.<br/>
* Value is first coerced to a <tt>double</tt> ( See <tt>coerceValueToDouble()</tt> ).
- * Note - <tt>BlankEval</tt> is converted to <code>0</code>.<p/>
- *
+ * Note - <tt>BlankEval</tt> is converted to <code>0</code>.<p/>
+ *
* Excel typically converts doubles to integers by truncating toward negative infinity.<br/>
* The equivalent java code is:<br/>
* <code>return (int)Math.floor(d);</code><br/>
* <b>not</b>:<br/>
- * <code>return (int)d; // wrong - rounds toward zero</code>
- *
+ * <code>return (int)d; // wrong - rounds toward zero</code>
+ *
*/
public static int coerceValueToInt(ValueEval ev) throws EvaluationException {
if (ev == BlankEval.INSTANCE) {
/**
* Applies some conversion rules if the supplied value is not already a number.
- * Note - <tt>BlankEval</tt> is converted to {@link NumberEval#ZERO}.
- * @param ev must be a {@link NumberEval}, {@link StringEval}, {@link BoolEval} or
+ * Note - <tt>BlankEval</tt> is converted to {@link NumberEval#ZERO}.
+ * @param ev must be a {@link NumberEval}, {@link StringEval}, {@link BoolEval} or
* {@link BlankEval}
* @return actual, parsed or interpreted double value (respectively).
* @throws EvaluationException(#VALUE!) only if a StringEval is supplied and cannot be parsed
* as a double (See <tt>parseDouble()</tt> for allowable formats).
- * @throws RuntimeException if the supplied parameter is not {@link NumberEval},
+ * @throws RuntimeException if the supplied parameter is not {@link NumberEval},
* {@link StringEval}, {@link BoolEval} or {@link BlankEval}
*/
public static double coerceValueToDouble(ValueEval ev) throws EvaluationException {
/**
* Converts a string to a double using standard rules that Excel would use.<br/>
* Tolerates currency prefixes, commas, leading and trailing spaces.<p/>
- *
- * Some examples:<br/>
+ *
+ * Some examples:<br/>
* " 123 " -> 123.0<br/>
* ".123" -> 0.123<br/>
* These not supported yet:<br/>
* "$1.25E4" -> 12500.0<br/>
* "5**2" -> 500<br/>
* "250%" -> 2.5<br/>
- *
- * @param pText
+ *
* @return <code>null</code> if the specified text cannot be parsed as a number
*/
public static Double parseDouble(String pText) {
return aeA.offset(top-aeAfr, bottom-aeAfr, left-aeAfc, right-aeAfc);
}
- private static AreaEval evaluateRef(Eval arg) throws EvaluationException {
+ private static AreaEval evaluateRef(ValueEval arg) throws EvaluationException {
if (arg instanceof AreaEval) {
return (AreaEval) arg;
}
*/
abstract class TwoOperandNumericOperation implements OperationEval {
- protected final double singleOperandEvaluate(Eval arg, int srcCellRow, short srcCellCol) throws EvaluationException {
+ protected final double singleOperandEvaluate(ValueEval arg, int srcCellRow, short srcCellCol) throws EvaluationException {
ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
return OperandResolver.coerceValueToDouble(ve);
}
throw new RuntimeException("function name argument missing");
}
- Eval nameArg = args[0];
+ ValueEval nameArg = args[0];
FreeRefFunction targetFunc;
if (nameArg instanceof NameEval) {
targetFunc = findInternalUserDefinedFunction((NameEval) nameArg);
-/*
-* 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 8, 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;
/**
* @author Amol S. Deshmukh < amolweb at ya hoo dot com >
- *
*/
-public interface ValueEval extends Eval {
-
+public interface ValueEval {
+ // no methods
}
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.ValueEval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.RefEval;
-import org.apache.poi.hssf.record.formula.eval.ValueEval;
/**
* Here are the general rules concerning Boolean functions:
return BoolEval.valueOf(boolResult);
}
- private boolean calculate(Eval[] args) throws EvaluationException {
+ private boolean calculate(ValueEval[] args) throws EvaluationException {
boolean result = getInitialResultValue();
boolean atleastOneNonBlank = false;
* Note: no short-circuit boolean loop exit because any ErrorEvals will override the result
*/
for (int i=0, iSize=args.length; i<iSize; i++) {
- Eval arg = args[i];
+ ValueEval arg = args[i];
if (arg instanceof AreaEval) {
AreaEval ae = (AreaEval) arg;
int height = ae.getHeight();
if (arg instanceof RefEval) {
ValueEval ve = ((RefEval) arg).getInnerValueEval();
tempVe = OperandResolver.coerceValueToBoolean(ve, true);
- } else if (arg instanceof ValueEval) {
- ValueEval ve = (ValueEval) arg;
- tempVe = OperandResolver.coerceValueToBoolean(ve, false);
} else {
- throw new RuntimeException("Unexpected eval (" + arg.getClass().getName() + ")");
+ tempVe = OperandResolver.coerceValueToBoolean(arg, false);
}
import org.apache.poi.hssf.record.formula.eval.AreaEval;
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.NumberEval;
import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
// too many arguments
return ErrorEval.VALUE_INVALID;
}
- Eval firstArg = args[0];
+ ValueEval firstArg = args[0];
int result;
if (firstArg instanceof AreaEval) {
package org.apache.poi.hssf.record.formula.functions;
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.MissingArgEval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
private static final I_MatchPredicate predicate = new I_MatchPredicate() {
- public boolean matches(Eval valueEval) {
+ public boolean matches(ValueEval valueEval) {
if(valueEval instanceof NumberEval) {
// only numbers are counted
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.Eval;
import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
* Common interface for the matching criteria.
*/
public interface I_MatchPredicate {
- boolean matches(Eval x);
+ boolean matches(ValueEval x);
}
/**
* @return the number of evaluated cells in the range that match the specified criteria
}
return 0;
}
- public static int countArg(Eval eval, I_MatchPredicate criteriaPredicate) {
+ public static int countArg(ValueEval eval, I_MatchPredicate criteriaPredicate) {
if (eval == null) {
throw new IllegalArgumentException("eval must not be null");
}
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.NumberEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
import org.apache.poi.hssf.record.formula.functions.CountUtils.I_MatchPredicate;
private static final I_MatchPredicate predicate = new I_MatchPredicate() {
- public boolean matches(Eval valueEval) {
+ public boolean matches(ValueEval valueEval) {
// Note - observed behavior of Excel:
// Error values like #VALUE!, #REF!, #DIV/0!, #NAME? etc don't cause this COUNTA to return an error
// in fact, they seem to get counted
import org.apache.poi.hssf.record.formula.eval.BlankEval;
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
return String.valueOf(_value);
}
- public boolean matches(Eval x) {
+ public boolean matches(ValueEval x) {
double testValue;
if(x instanceof StringEval) {
// if the target(x) is a string, but parses as a number
return value ? 1 : 0;
}
- public boolean matches(Eval x) {
+ public boolean matches(ValueEval x) {
int testValue;
if(x instanceof StringEval) {
if (true) { // change to false to observe more intuitive behaviour
return ErrorConstants.getText(_value);
}
- public boolean matches(Eval x) {
+ public boolean matches(ValueEval x) {
if(x instanceof ErrorEval) {
int testValue = ((ErrorEval)x).getErrorCode();
return evaluate(testValue - _value);
return _pattern.pattern();
}
- public boolean matches(Eval x) {
+ public boolean matches(ValueEval x) {
if (x instanceof BlankEval) {
switch(getCode()) {
case CmpOp.NONE:
/**
* @return the number of evaluated cells in the range that match the specified criteria
*/
- private double countMatchingCellsInArea(Eval rangeArg, I_MatchPredicate criteriaPredicate) {
+ private double countMatchingCellsInArea(ValueEval rangeArg, I_MatchPredicate criteriaPredicate) {
if (rangeArg instanceof RefEval) {
return CountUtils.countMatchingCell((RefEval) rangeArg, criteriaPredicate);
* Creates a criteria predicate object for the supplied criteria arg
* @return <code>null</code> if the arg evaluates to blank.
*/
- /* package */ static I_MatchPredicate createCriteriaPredicate(Eval arg, int srcRowIndex, int srcColumnIndex) {
+ /* package */ static I_MatchPredicate createCriteriaPredicate(ValueEval arg, int srcRowIndex, int srcColumnIndex) {
- Eval evaluatedCriteriaArg = evaluateCriteriaArg(arg, srcRowIndex, srcColumnIndex);
+ ValueEval evaluatedCriteriaArg = evaluateCriteriaArg(arg, srcRowIndex, srcColumnIndex);
if(evaluatedCriteriaArg instanceof NumberEval) {
return new NumberMatcher(((NumberEval)evaluatedCriteriaArg).getNumberValue(), CmpOp.OP_NONE);
*
* @return the de-referenced criteria arg (possibly {@link ErrorEval})
*/
- private static Eval evaluateCriteriaArg(Eval arg, int srcRowIndex, int srcColumnIndex) {
+ private static ValueEval evaluateCriteriaArg(ValueEval arg, int srcRowIndex, int srcColumnIndex) {
try {
return OperandResolver.getSingleValue(arg, srcRowIndex, (short)srcColumnIndex);
} catch (EvaluationException e) {
package org.apache.poi.hssf.record.formula.functions;
-import org.apache.poi.hssf.record.formula.eval.Eval;
import org.apache.poi.hssf.record.formula.eval.ErrorEval;
-import org.apache.poi.hssf.record.formula.eval.ValueEval;
-import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.EvaluationException;
+import org.apache.poi.hssf.record.formula.eval.NumberEval;
+import org.apache.poi.hssf.record.formula.eval.ValueEval;
/**
* Implementation of the FIND() function.<p/>
*/
public final class Find extends TextFunction {
- protected ValueEval evaluateFunc(Eval[] args, int srcCellRow, short srcCellCol)
+ protected ValueEval evaluateFunc(ValueEval[] args, int srcCellRow, short srcCellCol)
throws EvaluationException {
int nArgs = args.length;
import org.apache.poi.hssf.record.formula.eval.AreaEval;
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
public final class Hlookup implements Function {
public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
- Eval arg3 = null;
+ ValueEval arg3 = null;
switch(args.length) {
case 4:
arg3 = args[3]; // important: assumed array element is never null
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.MissingArgEval;
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
// too few arguments
return ErrorEval.VALUE_INVALID;
}
- Eval firstArg = args[0];
+ ValueEval firstArg = args[0];
if (firstArg instanceof RefEval) {
// convert to area ref for simpler code in getValueFromArea()
firstArg = ((RefEval)firstArg).offset(0, 0, 0, 0);
* @return the resolved 1-based index. Zero if the arg was missing or blank
* @throws EvaluationException if the arg is an error value evaluates to a negative numeric value
*/
- private static int resolveIndexArg(Eval arg, int srcCellRow, short srcCellCol) throws EvaluationException {
+ private static int resolveIndexArg(ValueEval arg, int srcCellRow, short srcCellCol) throws EvaluationException {
ValueEval ev = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
if (ev == MissingArgEval.instance) {
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
if(args.length != 1) {
return ErrorEval.VALUE_INVALID;
}
- Eval arg = args[0];
+ ValueEval arg = args[0];
try {
OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
import org.apache.poi.hssf.record.formula.eval.BlankEval;
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
if(args.length != 1) {
return ErrorEval.VALUE_INVALID;
}
- Eval arg = args[0];
+ ValueEval arg = args[0];
ValueEval singleCellValue;
try {
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.RefEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
return ErrorEval.VALUE_INVALID;
}
- Eval eval = operands[0];
+ ValueEval eval = operands[0];
if (eval instanceof RefEval || eval instanceof AreaEval) {
return BoolEval.TRUE;
}
import org.apache.poi.hssf.record.formula.eval.BlankEval;
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
* @return column or row index as a zero-based value, never negative.
* @throws EvaluationException when the specified arg cannot be coerced to a non-negative integer
*/
- public static int resolveRowOrColIndexArg(Eval rowColIndexArg, int srcCellRow, int srcCellCol) throws EvaluationException {
+ public static int resolveRowOrColIndexArg(ValueEval rowColIndexArg, int srcCellRow, int srcCellCol) throws EvaluationException {
if(rowColIndexArg == null) {
throw new IllegalArgumentException("argument must not be null");
}
* The second argument (table_array) should be an area ref, but can actually be a cell ref, in
* which case it is interpreted as a 1x1 area ref. Other scalar values cause #VALUE! error.
*/
- public static AreaEval resolveTableArrayArg(Eval eval) throws EvaluationException {
+ public static AreaEval resolveTableArrayArg(ValueEval eval) throws EvaluationException {
if (eval instanceof AreaEval) {
return (AreaEval) eval;
}
* @return
* @throws EvaluationException
*/
- public static boolean resolveRangeLookupArg(Eval rangeLookupArg, int srcCellRow, short srcCellCol) throws EvaluationException {
+ public static boolean resolveRangeLookupArg(ValueEval rangeLookupArg, int srcCellRow, short srcCellCol) throws EvaluationException {
if(rangeLookupArg == null) {
// range_lookup arg not provided
return true; // default is TRUE
import org.apache.poi.hssf.record.formula.eval.AreaEval;
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
}
}
- private static ValueVector evaluateLookupRange(Eval eval) throws EvaluationException {
+ private static ValueVector evaluateLookupRange(ValueEval eval) throws EvaluationException {
if (eval instanceof RefEval) {
RefEval re = (RefEval) eval;
return new SingleValueVector(re.getInnerValueEval());
- private static double evaluateMatchTypeArg(Eval arg, int srcCellRow, short srcCellCol)
+ private static double evaluateMatchTypeArg(ValueEval arg, int srcCellRow, short srcCellCol)
throws EvaluationException {
- Eval match_type = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
+ ValueEval match_type = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
if(match_type instanceof ErrorEval) {
throw new EvaluationException((ErrorEval)match_type);
import org.apache.poi.hssf.record.formula.eval.BlankEval;
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.RefEval;
return new NumberEval(result);
}
- private static void collectValues(Eval arg, List<Double> temp) throws EvaluationException {
+ private static void collectValues(ValueEval arg, List<Double> temp) throws EvaluationException {
if (arg instanceof AreaEval) {
AreaEval ae = (AreaEval) arg;
int width = ae.getWidth();
}
- private static void collectValue(Eval arg, List<Double> temp, boolean mustBeNumber)
+ private static void collectValue(ValueEval arg, List<Double> temp, boolean mustBeNumber)
throws EvaluationException {
if (arg instanceof ErrorEval) {
throw new EvaluationException((ErrorEval) arg);
import org.apache.poi.hssf.record.formula.eval.BlankEval;
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
*
* @return never <code>null</code>
*/
- protected final double[] getNumberArray(Eval[] operands) throws EvaluationException {
+ protected final double[] getNumberArray(ValueEval[] operands) throws EvaluationException {
if (operands.length > getMaxNumOperands()) {
throw EvaluationException.invalidValue();
}
/**
* Collects values from a single argument
*/
- private void collectValues(Eval operand, DoubleList temp) throws EvaluationException {
+ private void collectValues(ValueEval operand, DoubleList temp) throws EvaluationException {
if (operand instanceof AreaEval) {
AreaEval ae = (AreaEval) operand;
collectValue(re.getInnerValueEval(), true, temp);
return;
}
- collectValue((ValueEval)operand, false, temp);
+ collectValue(operand, false, temp);
}
private void collectValue(ValueEval ve, boolean isViaReference, DoubleList temp) throws EvaluationException {
if (ve == null) {
package org.apache.poi.hssf.record.formula.functions;
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
static final double TEN = 10.0;
static final double LOG_10_TO_BASE_e = Math.log(TEN);
- protected static final double singleOperandEvaluate(Eval arg, int srcCellRow, short srcCellCol) throws EvaluationException {
+ protected static final double singleOperandEvaluate(ValueEval arg, int srcCellRow, short srcCellCol) throws EvaluationException {
ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
double result = OperandResolver.coerceValueToDouble(ve);
checkValue(result);
return new NumberEval(result);
}
- protected abstract double eval(Eval[] args, int srcCellRow, short srcCellCol) throws EvaluationException;
+ protected abstract double eval(ValueEval[] args, int srcCellRow, short srcCellCol) throws EvaluationException;
/* -------------------------------------------------------------------------- */
// intermediate sub-classes (one-arg, two-arg and multi-arg)
protected OneArg() {
// no fields to initialise
}
- protected final double eval(Eval[] args, int srcCellRow, short srcCellCol) throws EvaluationException {
+ protected final double eval(ValueEval[] args, int srcCellRow, short srcCellCol) throws EvaluationException {
if (args.length != 1) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
protected TwoArg() {
// no fields to initialise
}
- protected final double eval(Eval[] args, int srcCellRow, short srcCellCol) throws EvaluationException {
+ protected final double eval(ValueEval[] args, int srcCellRow, short srcCellCol) throws EvaluationException {
if (args.length != 2) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
_minArgs = minArgs;
_maxArgs = maxArgs;
}
- protected final double eval(Eval[] args, int srcCellRow, short srcCellCol) throws EvaluationException {
+ protected final double eval(ValueEval[] args, int srcCellRow, short srcCellCol) throws EvaluationException {
int nArgs = args.length;
if (nArgs < _minArgs || nArgs > _maxArgs) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
return baseRef.offset(orRow.getFirstIndex(), orRow.getLastIndex(), orCol.getFirstIndex(), orCol.getLastIndex());
}
- private static BaseRef evaluateBaseRef(Eval eval) throws EvaluationException {
+ private static BaseRef evaluateBaseRef(ValueEval eval) throws EvaluationException {
if(eval instanceof RefEval) {
return new BaseRef((RefEval)eval);
/**
* OFFSET's numeric arguments (2..5) have similar processing rules
*/
- private static int evaluateIntArg(Eval eval, int srcCellRow, short srcCellCol) throws EvaluationException {
+ private static int evaluateIntArg(ValueEval eval, int srcCellRow, short srcCellCol) throws EvaluationException {
double d = evaluateDoubleArg(eval, srcCellRow, srcCellCol);
return convertDoubleToInt(d);
return (int)Math.floor(d);
}
- private static double evaluateDoubleArg(Eval eval, int srcCellRow, short srcCellCol) throws EvaluationException {
+ private static double evaluateDoubleArg(ValueEval eval, int srcCellRow, short srcCellCol) throws EvaluationException {
ValueEval ve = OperandResolver.getSingleValue(eval, srcCellRow, srcCellCol);
if (ve instanceof NumericValueEval) {
package org.apache.poi.hssf.record.formula.functions;
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.StringEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
*/
public final class Replace extends TextFunction {
- protected ValueEval evaluateFunc(Eval[] args, int srcCellRow, short srcCellCol)
+ protected ValueEval evaluateFunc(ValueEval[] args, int srcCellRow, short srcCellCol)
throws EvaluationException {
if (args.length != 4) {
return ErrorEval.VALUE_INVALID;
import org.apache.poi.hssf.record.formula.eval.AreaEval;
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.NumberEval;
import org.apache.poi.hssf.record.formula.eval.RefEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
// too many arguments
return ErrorEval.VALUE_INVALID;
}
- Eval firstArg = args[0];
+ ValueEval firstArg = args[0];
int result;
if (firstArg instanceof AreaEval) {
package org.apache.poi.hssf.record.formula.functions;
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.StringEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
*/
public final class Substitute extends TextFunction {
- protected ValueEval evaluateFunc(Eval[] args, int srcCellRow, short srcCellCol)
+ protected ValueEval evaluateFunc(ValueEval[] args, int srcCellRow, short srcCellCol)
throws EvaluationException {
if (args.length < 3 || args.length > 4) {
return ErrorEval.VALUE_INVALID;
import org.apache.poi.hssf.record.formula.eval.AreaEval;
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.RefEval;
* @return a range of the same dimensions as aeRange using eval to define the top left corner.
* @throws EvaluationException if eval is not a reference
*/
- private static AreaEval createSumRange(Eval eval, AreaEval aeRange) throws EvaluationException {
+ private static AreaEval createSumRange(ValueEval eval, AreaEval aeRange) throws EvaluationException {
if (eval instanceof AreaEval) {
return ((AreaEval) eval).offset(0, aeRange.getHeight()-1, 0, aeRange.getWidth()-1);
}
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
- private static AreaEval convertRangeArg(Eval eval) throws EvaluationException {
+ private static AreaEval convertRangeArg(ValueEval eval) throws EvaluationException {
if (eval instanceof AreaEval) {
return (AreaEval) eval;
}
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
protected static final String EMPTY_STRING = "";
- protected static final String evaluateStringArg(Eval eval, int srcRow, short srcCol) throws EvaluationException {
+ protected static final String evaluateStringArg(ValueEval eval, int srcRow, short srcCol) throws EvaluationException {
ValueEval ve = OperandResolver.getSingleValue(eval, srcRow, srcCol);
return OperandResolver.coerceValueToString(ve);
}
- protected static final int evaluateIntArg(Eval arg, int srcCellRow, short srcCellCol) throws EvaluationException {
+ protected static final int evaluateIntArg(ValueEval arg, int srcCellRow, short srcCellCol) throws EvaluationException {
ValueEval ve = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
return OperandResolver.coerceValueToInt(ve);
}
}
}
- protected abstract ValueEval evaluateFunc(Eval[] args, int srcCellRow, short srcCellCol) throws EvaluationException;
+ protected abstract ValueEval evaluateFunc(ValueEval[] args, int srcCellRow, short srcCellCol) throws EvaluationException;
/* ---------------------------------------------------------------------- */
protected SingleArgTextFunc() {
// no fields to initialise
}
- protected ValueEval evaluateFunc(Eval[] args, int srcCellRow, short srcCellCol)
+ protected ValueEval evaluateFunc(ValueEval[] args, int srcCellRow, short srcCellCol)
throws EvaluationException {
if (args.length != 1) {
return ErrorEval.VALUE_INVALID;
*/
public static final Function MID = new TextFunction() {
- protected ValueEval evaluateFunc(Eval[] args, int srcCellRow, short srcCellCol)
+ protected ValueEval evaluateFunc(ValueEval[] args, int srcCellRow, short srcCellCol)
throws EvaluationException {
if (args.length != 3) {
return ErrorEval.VALUE_INVALID;
protected LeftRight(boolean isLeft) {
_isLeft = isLeft;
}
- protected ValueEval evaluateFunc(Eval[] args, int srcCellRow, short srcCellCol)
+ protected ValueEval evaluateFunc(ValueEval[] args, int srcCellRow, short srcCellCol)
throws EvaluationException {
if (args.length != 2) {
return ErrorEval.VALUE_INVALID;
public static final Function CONCATENATE = new TextFunction() {
- protected ValueEval evaluateFunc(Eval[] args, int srcCellRow, short srcCellCol)
+ protected ValueEval evaluateFunc(ValueEval[] args, int srcCellRow, short srcCellCol)
throws EvaluationException {
StringBuffer sb = new StringBuffer();
for (int i=0, iSize=args.length; i<iSize; i++) {
public static final Function EXACT = new TextFunction() {
- protected ValueEval evaluateFunc(Eval[] args, int srcCellRow, short srcCellCol)
+ protected ValueEval evaluateFunc(ValueEval[] args, int srcCellRow, short srcCellCol)
throws EvaluationException {
if (args.length != 2) {
return ErrorEval.VALUE_INVALID;
package org.apache.poi.hssf.record.formula.functions;
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.MissingArgEval;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
}
return new NumberEval(result);
}
- private static int evalArg(Eval arg) throws EvaluationException {
+ private static int evalArg(ValueEval arg) throws EvaluationException {
if (arg == MissingArgEval.instance) {
return 0;
}
// Excel silently truncates double values to integers
- return OperandResolver.coerceValueToInt((ValueEval) arg);
+ return OperandResolver.coerceValueToInt(arg);
}
/**
* Converts the supplied hours, minutes and seconds to an Excel time value.
import org.apache.poi.hssf.record.formula.eval.AreaEval;
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.OperandResolver;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
public final class Vlookup implements Function {
public ValueEval evaluate(ValueEval[] args, int srcCellRow, short srcCellCol) {
- Eval arg3 = null;
+ ValueEval arg3 = null;
switch(args.length) {
case 4:
arg3 = args[3]; // important: assumed array element is never null
import org.apache.poi.hssf.record.formula.eval.AreaEval;
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.EvaluationException;
import org.apache.poi.hssf.record.formula.eval.NumberEval;
import org.apache.poi.hssf.record.formula.eval.RefEval;
return result;
}
- private static ValueVector createValueVector(Eval arg) throws EvaluationException {
+ private static ValueVector createValueVector(ValueEval arg) throws EvaluationException {
if (arg instanceof ErrorEval) {
throw new EvaluationException((ErrorEval) arg);
}
if (arg instanceof RefEval) {
return new RefValueArray((RefEval) arg);
}
- if (arg instanceof ValueEval) {
- return new SingleCellValueArray((ValueEval) arg);
- }
- throw new RuntimeException("Unexpected eval class (" + arg.getClass().getName() + ")");
+ return new SingleCellValueArray(arg);
}
}
import junit.framework.AssertionFailedError;
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.ValueEval;
import org.apache.poi.hssf.record.formula.eval.NumericValueEval;
import org.apache.poi.hssf.record.formula.eval.OperationEval;
import org.apache.poi.hssf.record.formula.eval.ValueEval;
*/
private static double invokeInternal(Object target, ValueEval[] args, int srcCellRow, int srcCellCol)
throws NumericEvalEx {
- Eval evalResult;
+ ValueEval evalResult;
// TODO - make OperationEval extend Function
try {
if (target instanceof Function) {