22 import ca.uqac.lif.cep.Context;
23 import ca.uqac.lif.cep.EventTracker;
24 import ca.uqac.lif.cep.functions.Function;
25 import ca.uqac.lif.cep.util.Booleans;
26 import ca.uqac.lif.cep.util.Numbers;
37 public static void main(String[] args)
41 Function negation = Booleans.not;
44 Object[] out =
new Object[1];
48 negation.evaluate(
new Object[]{
true}, out);
51 System.out.println(
"The return value of the function is: " + out[0]);
56 Function addition = Numbers.addition;
60 addition.evaluate(
new Object[]{2, 3}, out);
63 System.out.println(
"The return value of the function is: " + out[0]);
70 Function int_division = IntegerDivision.instance;
71 Object[] outs =
new Object[2];
72 int_division.evaluate(
new Object[]{14, 3}, outs);
73 System.out.println(
"14 divided by 3 equals " +
74 outs[0] +
" remainder " + outs[1]);
84 public static class IntegerDivision
extends Function
90 public static final transient IntegerDivision instance =
new IntegerDivision();
95 private IntegerDivision()
101 public Function duplicate(
boolean with_state)
107 public void evaluate(Object[] inputs, Object[] outputs, Context c, EventTracker t)
109 int x = (Integer) inputs[0];
110 int y = (Integer) inputs[1];
116 public int getInputArity()
122 public int getOutputArity()
134 public void getInputTypesFor(Set<Class<?>> classes,
int index)
136 classes.add(Number.class);
140 public Class<?> getOutputTypeFor(
int index)
142 return Integer.class;
static void main(String[] args)
Show the basic usage of Function objects.