Code Examples
A repository of 155 code examples for BeepBeep
DuplicateNoState.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 basic;
19 
20 import ca.uqac.lif.cep.Connector;
21 import ca.uqac.lif.cep.Pushable;
22 import ca.uqac.lif.cep.functions.Cumulate;
23 import ca.uqac.lif.cep.functions.CumulativeFunction;
24 import ca.uqac.lif.cep.io.Print;
25 import ca.uqac.lif.cep.util.Numbers;
26 
27 /**
28  * Duplicating processors without preserving their state.
29  *
30  * @author Sylvain HallĂ©
31  * @difficulty Easy
32  */
33 public class DuplicateNoState
34 {
35  public static void main(String[] args)
36  {
37  /// We first create a cumulative processor and a simple GroupProcessor
38  Cumulate sum1 = new Cumulate(
39  new CumulativeFunction<Number>(Numbers.addition));
40  Connector.connect(sum1, new Print()
41  .setPrefix("sum1: ").setSeparator("\n"));
42 
43  // We then feed a few events to each of them
44  Pushable p_sum1 = sum1.getPushableInput();
45  p_sum1.push(3).push(1).push(4);
46  ///
47 
48  //* Let us now duplicate sum1 and push events to the copy
49  Cumulate sum2 = (Cumulate) sum1.duplicate();
50  Connector.connect(sum2, new Print()
51  .setPrefix("sum2: ").setSeparator("\n"));
52  Pushable p_sum2 = sum2.getPushableInput();
53  p_sum2.push(2).push(7).push(1);
54  //*
55  }
56 }
static void main(String[] args)
Duplicating processors without preserving their state.