use of org.apache.poi.ss.formula.eval.NumericValueEval in project poi by apache.
the class Match method evaluateLookupRange.
private static ValueVector evaluateLookupRange(ValueEval eval) throws EvaluationException {
if (eval instanceof RefEval) {
RefEval re = (RefEval) eval;
if (re.getNumberOfSheets() == 1) {
return new SingleValueVector(re.getInnerValueEval(re.getFirstSheetIndex()));
} else {
return LookupUtils.createVector(re);
}
}
if (eval instanceof TwoDEval) {
ValueVector result = LookupUtils.createVector((TwoDEval) eval);
if (result == null) {
throw new EvaluationException(ErrorEval.NA);
}
return result;
}
// Error handling for lookup_range arg is also unusual
if (eval instanceof NumericValueEval) {
throw new EvaluationException(ErrorEval.NA);
}
if (eval instanceof StringEval) {
StringEval se = (StringEval) eval;
Double d = OperandResolver.parseDouble(se.getStringValue());
if (d == null) {
// plain string
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
// else looks like a number
throw new EvaluationException(ErrorEval.NA);
}
throw new RuntimeException("Unexpected eval type (" + eval + ")");
}
use of org.apache.poi.ss.formula.eval.NumericValueEval in project poi by apache.
the class Match method evaluateMatchTypeArg.
private static double evaluateMatchTypeArg(ValueEval arg, int srcCellRow, int srcCellCol) throws EvaluationException {
ValueEval match_type = OperandResolver.getSingleValue(arg, srcCellRow, srcCellCol);
if (match_type instanceof ErrorEval) {
throw new EvaluationException((ErrorEval) match_type);
}
if (match_type instanceof NumericValueEval) {
NumericValueEval ne = (NumericValueEval) match_type;
return ne.getNumberValue();
}
if (match_type instanceof StringEval) {
StringEval se = (StringEval) match_type;
Double d = OperandResolver.parseDouble(se.getStringValue());
if (d == null) {
// plain string
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
// if the string parses as a number, it is OK
return d.doubleValue();
}
throw new RuntimeException("Unexpected match_type type (" + match_type.getClass().getName() + ")");
}
use of org.apache.poi.ss.formula.eval.NumericValueEval in project poi by apache.
the class MultiOperandNumericFunction method collectValue.
private void collectValue(ValueEval ve, boolean isViaReference, DoubleList temp) throws EvaluationException {
if (ve == null) {
throw new IllegalArgumentException("ve must not be null");
}
if (ve instanceof BoolEval) {
if (!isViaReference || _isReferenceBoolCounted) {
BoolEval boolEval = (BoolEval) ve;
temp.add(boolEval.getNumberValue());
}
return;
}
if (ve instanceof NumericValueEval) {
NumericValueEval ne = (NumericValueEval) ve;
temp.add(ne.getNumberValue());
return;
}
if (ve instanceof StringValueEval) {
if (isViaReference) {
// ignore all ref strings
return;
}
String s = ((StringValueEval) ve).getStringValue();
Double d = OperandResolver.parseDouble(s);
if (d == null) {
throw new EvaluationException(ErrorEval.VALUE_INVALID);
}
temp.add(d.doubleValue());
return;
}
if (ve instanceof ErrorEval) {
throw new EvaluationException((ErrorEval) ve);
}
if (ve == BlankEval.instance) {
if (_isBlankCounted) {
temp.add(0.0);
}
return;
}
throw new RuntimeException("Invalid ValueEval type passed for conversion: (" + ve.getClass() + ")");
}
use of org.apache.poi.ss.formula.eval.NumericValueEval in project poi by apache.
the class Sumproduct method evaluate.
public ValueEval evaluate(ValueEval[] args, int srcCellRow, int srcCellCol) {
int maxN = args.length;
if (maxN < 1) {
return ErrorEval.VALUE_INVALID;
}
ValueEval firstArg = args[0];
try {
if (firstArg instanceof NumericValueEval) {
return evaluateSingleProduct(args);
}
if (firstArg instanceof RefEval) {
return evaluateSingleProduct(args);
}
if (firstArg instanceof TwoDEval) {
TwoDEval ae = (TwoDEval) firstArg;
if (ae.isRow() && ae.isColumn()) {
return evaluateSingleProduct(args);
}
return evaluateAreaSumProduct(args);
}
} catch (EvaluationException e) {
return e.getErrorEval();
}
throw new RuntimeException("Invalid arg type for SUMPRODUCT: (" + firstArg.getClass().getName() + ")");
}
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();
}
Aggregations