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

net.sf.aguacate.function.spi.AbstractFunction2 Maven / Gradle / Ivy

There is a newer version: 0.10.9
Show newest version
package net.sf.aguacate.function.spi;

import java.text.MessageFormat;
import java.util.Collection;
import java.util.Map;

import net.sf.aguacate.function.FunctionContext;
import net.sf.aguacate.function.FunctionEvalResult;
import net.sf.aguacate.util.parameter.Parameter;

public abstract class AbstractFunction2 extends AbstractFunction {

	private final Parameter parameter1;

	private final Parameter parameter2;

	private final String message;

	public AbstractFunction2(Collection methods, String name, String message, Parameter parameter1,
			Parameter parameter2) {
		super(methods, name);
		this.parameter1 = parameter1;
		this.parameter2 = parameter2;
		this.message = message;
	}

	@Override
	public FunctionEvalResult evaluate(FunctionContext functionContext, Map context) {
		Object value1 = parameter1.calculateContext(context).get(parameter1.getName());
		Object value2 = parameter2.calculateContext(context).get(parameter2.getName());
		String msg = MessageFormat.format(message, value1, value2);
		return evaluate(msg, value1, value2);
	}

	protected abstract FunctionEvalResult evaluate(String msg, Object value1, Object value2);

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy