net.sf.aguacate.function.spi.impl.FunctionConditional 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.check.Check;
import net.sf.aguacate.check.CheckCoupling;
import net.sf.aguacate.function.Function;
import net.sf.aguacate.function.FunctionContext;
import net.sf.aguacate.function.FunctionEvalResult;
import net.sf.aguacate.function.Parameter;
import net.sf.aguacate.function.spi.AbstractFunction;
import net.sf.aguacate.function.spi.FuncionExecutor;
/**
*
* {
* "name": "...",
* "message": "...",
* "type" : "CONDITIONAL",
* "test" : "type",
* "parameters" : [
* to_test
* ],
* "validations": [
* ...
* ],
* "methods": [
* ...
* ]
* }
*
*/
public class FunctionConditional extends AbstractFunction {
private static final Logger LOGGER = LogManager.getLogger(FunctionConditional.class);
private static final FunctionEvalResult DEFAULT = new FunctionEvalResult(null, null);
private final Function[] functions;
private final String checkName;
private final Check check;
private final Parameter parameter;
public FunctionConditional(Collection methods, String name, String message, Parameter parameter,
List list, String check) {
super(methods, name);
this.functions = list.toArray(new Function[list.size()]);
this.checkName = check;
this.check = CheckCoupling.get(check);
this.parameter = parameter;
}
@Override
public FunctionEvalResult evaluate(FunctionContext functionContext, Map context) {
LOGGER.debug(checkName);
if (check.test(context.get(parameter.getName()))) {
LOGGER.trace("{}: true", checkName);
return FuncionExecutor.execute(functions, functionContext, context);
}
return DEFAULT;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy