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

net.sf.aguacate.function.spi.impl.FunctionCreateContext 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.LinkedHashMap;
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.spi.AbstractFunction;
import net.sf.aguacate.util.parameter.Parameter;
import net.sf.aguacate.util.type.Str;

public class FunctionCreateContext extends AbstractFunction {

	private final String[] outputContext;

	private final String outputName;

	private final Parameter[] parameters;

	public FunctionCreateContext(Collection methods, String name, Collection parameters,
			List outputContext, String outputName) {
		super(methods, name);
		this.parameters = parameters.toArray(new Parameter[parameters.size()]);
		this.outputContext = Str.toArray(outputContext);
		this.outputName = outputName;
	}

	@Override
	public FunctionEvalResult evaluate(FunctionContext functionContext, Map context) {
		Map ctx = new LinkedHashMap<>();
		for (Parameter parameter : parameters) {
			Map temp = parameter.calculateContext(context);
			String name = parameter.getName();
			ctx.put(name, temp.get(name));
		}
		return new FunctionEvalResult(true, ctx);
	}

	@Override
	public String[] getOutputContext() {
		return outputContext;
	}

	@Override
	public String getOutputName() {
		return outputName;
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy