20 import ca.uqac.lif.cep.Connector;
21 import static ca.uqac.lif.cep.Connector.INPUT;
22 import static ca.uqac.lif.cep.Connector.OUTPUT;
23 import ca.uqac.lif.cep.GroupProcessor;
24 import ca.uqac.lif.cep.Pullable;
25 import ca.uqac.lif.cep.functions.Constant;
26 import ca.uqac.lif.cep.functions.Cumulate;
27 import ca.uqac.lif.cep.functions.CumulativeFunction;
28 import ca.uqac.lif.cep.functions.Function;
29 import ca.uqac.lif.cep.functions.IdentityFunction;
30 import ca.uqac.lif.cep.functions.TurnInto;
31 import ca.uqac.lif.cep.tmf.QueueSource;
32 import ca.uqac.lif.cep.tmf.Slice;
33 import ca.uqac.lif.cep.util.Numbers;
77 public static void main(String[] args)
80 QueueSource source =
new QueueSource();
81 source.setEvents(1, 6, 4, 3, 2, 1, 9);
85 Function slicing_fct =
new IdentityFunction(1);
89 GroupProcessor counter =
new GroupProcessor(1, 1);
91 TurnInto to_one =
new TurnInto(
new Constant(1));
92 Cumulate sum =
new Cumulate(
93 new CumulativeFunction<Number>(Numbers.addition));
94 Connector.connect(to_one, sum);
95 counter.addProcessors(to_one, sum);
96 counter.associateInput(INPUT, to_one, INPUT);
97 counter.associateOutput(OUTPUT, sum, OUTPUT);
102 Slice slicer =
new Slice(slicing_fct, counter);
103 Connector.connect(source, slicer);
106 Pullable p = slicer.getPullableOutput();
107 for (
int i = 0; i < 10; i++)
110 System.out.println(o);
Use the SlicerMap to perform a computation on multiple subsets of an input stream.
static void main(String[] args)