net.sf.aguacate.function.spi.AbstractFunctionN Maven / Gradle / Ivy
package net.sf.aguacate.function.spi;
import java.text.MessageFormat;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import net.sf.aguacate.function.FunctionContext;
import net.sf.aguacate.function.FunctionEvalResult;
import net.sf.aguacate.function.Parameter;
public abstract class AbstractFunctionN extends AbstractFunction {
private final Parameter[] parameters;
private final String message;
public AbstractFunctionN(Collection methods, String name, String message, List parameters) {
super(methods, name);
this.parameters = parameters.toArray(new Parameter[parameters.size()]);
this.message = message;
}
@Override
public FunctionEvalResult evaluate(FunctionContext functionContext, Map context) {
int length = parameters.length;
Object[] values = new Object[length];
for (int i = 0; i < length; i++) {
values[i] = context.get(parameters[i].getName());
}
String msg = MessageFormat.format(message, values);
return evaluate(functionContext, values, msg);
}
protected abstract FunctionEvalResult evaluate(FunctionContext functionContext, Object[] values, String msg);
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy