jadex.rules.eca.CommandCondition Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of jadex-rules-eca Show documentation
Show all versions of jadex-rules-eca Show documentation
Small Java annotation-based event-condition-action rule engine.
package jadex.rules.eca;
import jadex.commons.IResultCommand;
import jadex.commons.Tuple2;
import jadex.commons.future.DelegationResultListener;
import jadex.commons.future.ExceptionDelegationResultListener;
import jadex.commons.future.Future;
import jadex.commons.future.IFuture;
/**
* Command version of the condition.
*/
public class CommandCondition implements ICondition
{
/** The command. */
protected IResultCommand command;
/**
*
*/
public CommandCondition(IResultCommand command)
{
this.command = command;
}
/**
*
*/
public IFuture> evaluate(IEvent event)
{
Object res = command.execute(event);
return evaluateResult(res);
}
/**
*
*/
public static IFuture> evaluateResult(Object res)
{
final Future> ret = new Future>();
if(res==null)
{
ret.setResult(new Tuple2(Boolean.FALSE, null));
}
else if(res instanceof Tuple2)
{
ret.setResult((Tuple2)res);
}
else if(res instanceof Boolean)
{
boolean bs = ((Boolean)res).booleanValue();
ret.setResult(bs? ICondition.TRUE: ICondition.FALSE);
}
else if(res instanceof Future)
{
((Future