use of org.apache.poi.ss.formula.eval.FunctionNameEval in project poi by apache.
the class UserDefinedFunction method evaluate.
public ValueEval evaluate(ValueEval[] args, OperationEvaluationContext ec) {
int nIncomingArgs = args.length;
if (nIncomingArgs < 1) {
throw new RuntimeException("function name argument missing");
}
ValueEval nameArg = args[0];
String functionName;
if (nameArg instanceof FunctionNameEval) {
functionName = ((FunctionNameEval) nameArg).getFunctionName();
} else {
throw new RuntimeException("First argument should be a NameEval, but got (" + nameArg.getClass().getName() + ")");
}
FreeRefFunction targetFunc = ec.findUserDefinedFunction(functionName);
if (targetFunc == null) {
throw new NotImplementedFunctionException(functionName);
}
int nOutGoingArgs = nIncomingArgs - 1;
ValueEval[] outGoingArgs = new ValueEval[nOutGoingArgs];
System.arraycopy(args, 1, outGoingArgs, 0, nOutGoingArgs);
return targetFunc.evaluate(outGoingArgs, ec);
}
Aggregations