Code Examples
A repository of 155 code examples for BeepBeep
RunOnExample.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2018 Sylvain HallĂ©
4 
5  This program is free software: you can redistribute it and/or modify
6  it under the terms of the GNU Lesser General Public License as published
7  by the Free Software Foundation, either version 3 of the License, or
8  (at your option) any later version.
9 
10  This program is distributed in the hope that it will be useful,
11  but WITHOUT ANY WARRANTY; without even the implied warranty of
12  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13  GNU Lesser General Public License for more details.
14 
15  You should have received a copy of the GNU Lesser General Public License
16  along with this program. If not, see <http://www.gnu.org/licenses/>.
17  */
18 package util;
19 
20 import ca.uqac.lif.cep.Connector;
21 import ca.uqac.lif.cep.Pullable;
22 import ca.uqac.lif.cep.UtilityMethods;
23 import ca.uqac.lif.cep.functions.Cumulate;
24 import ca.uqac.lif.cep.functions.CumulativeFunction;
25 import ca.uqac.lif.cep.tmf.QueueSource;
26 import ca.uqac.lif.cep.util.Bags;
27 import ca.uqac.lif.cep.util.Numbers;
28 
29 /**
30  * Apply a processor on collections of events
31  * using the {@link ca.uqac.cep.util.Bags.RunOn RunOn} processor.
32  * Graphically, this chain of processors can be represented as:
33  * <p>
34  * <img src="./doc-files/util/RunOnExample.png" alt="Processor graph">
35  * <p>
36  * The output of this program is:
37  * <pre>
38  * 9.0
39  * 6.0
40  * 16.0
41  * 10.0
42  * </pre>
43  * @author Sylvain HallĂ©
44  *
45  */
46 public class RunOnExample
47 {
48  public static void main(String[] args)
49  {
50  ///
51  QueueSource src1 = new QueueSource();
52  src1.addEvent(UtilityMethods.createList(1f, 3f, 5f));
53  src1.addEvent(UtilityMethods.createList(4f, 2f));
54  src1.addEvent(UtilityMethods.createList(4f, 4f, 8f));
55  src1.addEvent(UtilityMethods.createList(6f, 4f));
56  Bags.RunOn run = new Bags.RunOn(new Cumulate(
57  new CumulativeFunction<Number>(Numbers.addition)));
58  Connector.connect(src1, run);
59  Pullable p = run.getPullableOutput();
60  for (int i = 0; i < 4; i++)
61  {
62  System.out.println(p.pull());
63  }
64  ///
65  }
66 }
Apply a processor on collections of events using the RunOn processor.