All Downloads are FREE. Search and download functionalities are using the official Maven repository.

net.sf.aguacate.function.spi.impl.FunctionArrayIterator Maven / Gradle / Ivy

There is a newer version: 0.10.9
Show newest version
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.AbstractFunction1;
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 AbstractFunction1 { private static final Logger LOGGER = LogManager.getLogger(FunctionArrayIterator.class); 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, message, parameter); this.outputContext = Str.toArray(outputContext); this.outputName = outputName; this.functions = list.toArray(new Function[list.size()]); } @Override public FunctionEvalResult evaluate(FunctionContext functionContext, String msg, Object value) { @SuppressWarnings("unchecked") List> data = (List>) value; int size = data.size(); for (int i = 0; i < size; i++) { Map subcontext = data.get(i); LOGGER.trace("before subcontext: {}", subcontext); for (Function function : functions) { FunctionEvalResult result = function.evaluate(functionContext, subcontext); if (result.isSuccess()) { String outputName = function.getOutputName(); if (outputName != null) { subcontext.put(outputName, result.getData()); } } else { return result; } LOGGER.trace("in subcontext: {}", subcontext); } LOGGER.trace("after subcontext: {}", subcontext); } return new FunctionEvalResult(null, null); } @Override public String getOutputName() { return outputName; } @Override public String[] getOutputContext() { return outputContext; } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy