20 import static ca.uqac.lif.cep.Connector.INPUT;
21 import static ca.uqac.lif.cep.Connector.LEFT;
22 import static ca.uqac.lif.cep.Connector.OUTPUT;
23 import static ca.uqac.lif.cep.Connector.RIGHT;
24 import static ca.uqac.lif.cep.Connector.connect;
26 import ca.uqac.lif.cep.Pullable;
27 import ca.uqac.lif.cep.UtilityMethods;
28 import ca.uqac.lif.cep.functions.ApplyFunction;
29 import ca.uqac.lif.cep.tmf.CountDecimate;
30 import ca.uqac.lif.cep.tmf.Fork;
31 import ca.uqac.lif.cep.tmf.QueueSource;
32 import ca.uqac.lif.cep.tmf.Trim;
33 import ca.uqac.lif.cep.util.Numbers;
63 public static void main(String[] args)
66 QueueSource source_values =
new QueueSource();
67 source_values.setEvents(6, 5, 3, 8, 9, 2, 1, 7, 4, 5,
68 2, 4, 7, 6, 12, 8, 1);
71 Fork fork =
new Fork(2);
72 connect(source_values, fork);
76 ApplyFunction sum =
new ApplyFunction(Numbers.addition);
77 connect(fork, LEFT, sum, LEFT);
81 Trim trim =
new Trim(1);
82 connect(fork, RIGHT, trim, INPUT);
90 connect(trim, OUTPUT, sum, RIGHT);
96 CountDecimate decimate =
new CountDecimate(2);
97 connect(sum, OUTPUT, decimate, INPUT);
101 Pullable p = decimate.getPullableOutput();
102 for (
int i = 0; i < 9; i++)
104 int v = ((Number) p.pull()).intValue();
105 System.out.printf(
"Event #%d is: %d\n", i, v);
107 UtilityMethods.pause(1000);
Compute the sum of every pair of successive events.