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;
25 import ca.uqac.lif.cep.Connector;
26 import ca.uqac.lif.cep.Pullable;
27 import ca.uqac.lif.cep.UtilityMethods;
28 import ca.uqac.lif.cep.functions.CumulativeFunction;
29 import ca.uqac.lif.cep.functions.ApplyFunction;
30 import ca.uqac.lif.cep.functions.Cumulate;
31 import ca.uqac.lif.cep.tmf.QueueSource;
32 import ca.uqac.lif.cep.util.Numbers;
66 public static void main(String[] args)
69 UtilityMethods.printGreeting();
75 QueueSource numbers =
new QueueSource(1);
76 numbers.setEvents(
new Object[]{2, 7, 1, 8, 2, 8, 1, 8, 2, 8,
77 4, 5, 9, 0, 4, 5, 2, 3, 5, 3, 6, 0, 2, 8, 7});
85 Cumulate sum_proc =
new Cumulate(
86 new CumulativeFunction<Number>(Numbers.addition));
87 Connector.connect(numbers, OUTPUT, sum_proc, INPUT);
90 QueueSource counter =
new QueueSource().setEvents(1, 2, 3, 4, 5, 6, 7);
95 ApplyFunction division =
new ApplyFunction(Numbers.division);
96 Connector.connect(sum_proc, OUTPUT, division, LEFT);
97 Connector.connect(counter, OUTPUT, division, RIGHT);
101 Pullable p = division.getPullableOutput();
102 System.out.println(
"The cumulative average is...");
103 for (
int i = 0; i < 20; i++)
105 float value = (Float) p.pull();
106 System.out.print(value +
", ");
107 UtilityMethods.pause(1000);
109 System.out.println(
"done!");
Compute the cumulative average of a list of numbers.