Code Examples
A repository of 155 code examples for BeepBeep
RandomTwoD.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2017 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 plots;
19 
20 import static ca.uqac.lif.cep.Connector.INPUT;
21 import static ca.uqac.lif.cep.Connector.TOP;
22 import static ca.uqac.lif.cep.Connector.OUTPUT;
23 import static ca.uqac.lif.cep.Connector.BOTTOM;
24 
25 import ca.uqac.lif.cep.Connector;
26 import ca.uqac.lif.cep.GroupProcessor;
27 import ca.uqac.lif.cep.functions.Cumulate;
28 import ca.uqac.lif.cep.functions.CumulativeFunction;
29 import ca.uqac.lif.cep.tmf.Fork;
30 import ca.uqac.lif.cep.util.Numbers;
31 
32 /**
33  * Generates a random stream of x-y pairs. This processor internally forks
34  * an input of stream of numbers. The first fork is left as is and
35  * becomes the first output stream. The second fork is sent through a
36  * {@link RandomMutator} and becomes the second output stream.
37  * <p>
38  * Graphically, this can be described as follows:
39  * <p>
40  * <img src="./doc-files/plots/RandomTwoD.png" alt="Processor graph">
41  * <p>
42  * When used in other processor chains, this group processor will be
43  * represented as:
44  * <p>
45  * <img src="./doc-files/plots/RandomTwoD-box.png" alt="Processor graph">
46  *
47  * @author Sylvain HallĂ©
48  */
49 public class RandomTwoD extends GroupProcessor
50 {
51  public RandomTwoD()
52  {
53  super(1, 2);
54  Fork fork = new Fork(2);
55  associateInput(INPUT, fork, INPUT);
56  Cumulate sum = new Cumulate(new CumulativeFunction<Number>(Numbers.addition));
57  Connector.connect(fork, TOP, sum, INPUT);
58  RandomMutator random = new RandomMutator(0, 100);
59  Connector.connect(fork, BOTTOM, random, INPUT);
60  associateOutput(TOP, sum, OUTPUT);
61  associateOutput(BOTTOM, random, OUTPUT);
62  addProcessors(fork, sum, random);
63  }
64 }
Processor that converts any input into a random integer.
Generates a random stream of x-y pairs.
Definition: RandomTwoD.java:49