use of org.apache.poi.ss.formula.eval.NumericValueEval in project poi by apache.
the class NumericFunctionInvoker method invokeInternal.
/**
* Formats nicer error messages for the junit output
*/
private static double invokeInternal(Function target, ValueEval[] args, int srcCellRow, int srcCellCol) throws NumericEvalEx {
ValueEval evalResult;
try {
evalResult = target.evaluate(args, srcCellRow, (short) srcCellCol);
} catch (NotImplementedException e) {
throw new NumericEvalEx("Not implemented:" + e.getMessage());
}
if (evalResult == null) {
throw new NumericEvalEx("Result object was null");
}
if (evalResult instanceof ErrorEval) {
ErrorEval ee = (ErrorEval) evalResult;
throw new NumericEvalEx(formatErrorMessage(ee));
}
if (!(evalResult instanceof NumericValueEval)) {
throw new NumericEvalEx("Result object type (" + evalResult.getClass().getName() + ") is invalid. Expected implementor of (" + NumericValueEval.class.getName() + ")");
}
NumericValueEval result = (NumericValueEval) evalResult;
return result.getNumberValue();
}
use of org.apache.poi.ss.formula.eval.NumericValueEval in project poi by apache.
the class TestSumif method confirmDouble.
private static void confirmDouble(double expected, ValueEval actualEval) {
if (!(actualEval instanceof NumericValueEval)) {
throw new AssertionFailedError("Expected numeric result");
}
NumericValueEval nve = (NumericValueEval) actualEval;
assertEquals(expected, nve.getNumberValue(), 0);
}
use of org.apache.poi.ss.formula.eval.NumericValueEval in project poi by apache.
the class TestSumproduct method confirmDouble.
private static void confirmDouble(double expected, ValueEval actualEval) {
if (!(actualEval instanceof NumericValueEval)) {
fail("Expected numeric result");
}
NumericValueEval nve = (NumericValueEval) actualEval;
assertEquals(expected, nve.getNumberValue(), 0);
}
use of org.apache.poi.ss.formula.eval.NumericValueEval in project poi by apache.
the class LookupUtils method resolveRangeLookupArg.
/**
* Resolves the last (optional) parameter (<b>range_lookup</b>) to the VLOOKUP and HLOOKUP functions.
* @param rangeLookupArg must not be <code>null</code>
*/
public static boolean resolveRangeLookupArg(ValueEval rangeLookupArg, int srcCellRow, int srcCellCol) throws EvaluationException {
ValueEval valEval = OperandResolver.getSingleValue(rangeLookupArg, srcCellRow, srcCellCol);
if (valEval instanceof BlankEval) {
// this does not get the default value
return false;
}
if (valEval instanceof BoolEval) {
// Happy day flow
BoolEval boolEval = (BoolEval) valEval;
return boolEval.getBooleanValue();
}
if (valEval instanceof StringEval) {
String stringValue = ((StringEval) valEval).getStringValue();
if (stringValue.length() < 1) {
// Empty string is not the same as BlankEval. It causes #VALUE! error
throw EvaluationException.invalidValue();
}
// TODO move parseBoolean to OperandResolver
Boolean b = Countif.parseBoolean(stringValue);
if (b != null) {
// string converted to boolean OK
return b.booleanValue();
}
// Excel does not resolve it to a boolean.
throw EvaluationException.invalidValue();
// This is in contrast to the code below,, where NumberEvals values (for
// example 0.01) *do* resolve to equivalent boolean values.
}
if (valEval instanceof NumericValueEval) {
NumericValueEval nve = (NumericValueEval) valEval;
// zero is FALSE, everything else is TRUE
return 0.0 != nve.getNumberValue();
}
throw new RuntimeException("Unexpected eval type (" + valEval + ")");
}
Aggregations