use of org.apache.poi.ss.formula.LazyRefEval in project poi by apache.
the class Subtotal method evaluate.
public ValueEval evaluate(ValueEval[] args, int srcRowIndex, int srcColumnIndex) {
// -1: first arg is used to select from a basic aggregate function
int nInnerArgs = args.length - 1;
if (nInnerArgs < 1) {
return ErrorEval.VALUE_INVALID;
}
final Function innerFunc;
try {
ValueEval ve = OperandResolver.getSingleValue(args[0], srcRowIndex, srcColumnIndex);
int functionCode = OperandResolver.coerceValueToInt(ve);
innerFunc = findFunction(functionCode);
} catch (EvaluationException e) {
return e.getErrorEval();
}
// ignore the first arg, this is the function-type, we check for the length above
final List<ValueEval> list = new ArrayList<ValueEval>(Arrays.asList(args).subList(1, args.length));
Iterator<ValueEval> it = list.iterator();
// For array references it is handled in other evaluation steps, but we need to handle this here for references to subtotal-functions
while (it.hasNext()) {
ValueEval eval = it.next();
if (eval instanceof LazyRefEval) {
LazyRefEval lazyRefEval = (LazyRefEval) eval;
if (lazyRefEval.isSubTotal()) {
it.remove();
}
}
}
return innerFunc.evaluate(list.toArray(new ValueEval[list.size()]), srcRowIndex, srcColumnIndex);
}
Aggregations