net.sf.aguacate.function.spi.impl.FunctionArrayIterator Maven / Gradle / Ivy
package net.sf.aguacate.function.spi.impl;
import java.util.Collection;
import java.util.List;
import java.util.Map;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import net.sf.aguacate.function.Function;
import net.sf.aguacate.function.FunctionContext;
import net.sf.aguacate.function.FunctionEvalResult;
import net.sf.aguacate.function.spi.AbstractFunction;
import net.sf.aguacate.util.parameter.Parameter;
import net.sf.aguacate.util.type.Str;
/**
*
* {
* "name": "...",
* "message": "...",
* "type" : "STRUCTURE_ARRAY_ITERATOR",
* "parameters" : [
* ...
* ],
* "validations": [
* ...
* ],
* "methods": [
* ...
* ]
* }
*
*/
public class FunctionArrayIterator extends AbstractFunction {
private static final Logger LOGGER = LogManager.getLogger(FunctionArrayIterator.class);
private String message;
private Parameter parameter;
private final String[] outputContext;
private final String outputName;
private final Function[] functions;
public FunctionArrayIterator(Collection methods, String name, String message, Parameter parameter,
List outputContext, String outputName, List list) {
super(methods, name);
this.message = message;
this.parameter = parameter;
this.outputContext = Str.toArray(outputContext);
this.outputName = outputName;
this.functions = list.toArray(new Function[list.size()]);
}
@Override
@SuppressWarnings("unchecked")
public FunctionEvalResult evaluate(FunctionContext functionContext, Map context) {
Map working = calculateOutputContext(outputContext, context);
if (working.containsKey(outputName)) {
return new FunctionEvalResult(false, "Already defined: " + outputName, null);
} else {
List