Code Examples
A repository of 155 code examples for BeepBeep
FilterSimple.java
1 /*
2  BeepBeep, an event stream processor
3  Copyright (C) 2008-2016 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 static ca.uqac.lif.cep.Connector.TOP;
21 import static ca.uqac.lif.cep.Connector.OUTPUT;
22 import static ca.uqac.lif.cep.Connector.BOTTOM;
23 import static ca.uqac.lif.cep.Connector.connect;
24 import ca.uqac.lif.cep.Pullable;
25 import ca.uqac.lif.cep.tmf.Filter;
26 import ca.uqac.lif.cep.tmf.QueueSource;
27 
28 /**
29  * Discard events from an input trace with the
30  * {@link ca.uqac.lif.cep.tmf.Filter Filter} processor. This example can
31  * be represented grahpically as:
32  * <p>
33  * <img src="./doc-files/basic/FilterSimple.png" alt="Processor graph">
34  * @author Sylvain HallĂ©
35  * @difficulty Easy
36  */
37 public class FilterSimple
38 {
39  public static void main(String[] args)
40  {
41  /// Create a first trace of dummy values
42  QueueSource source_values = new QueueSource();
43  source_values.setEvents(6, 5, 3, 8, 9, 2, 1, 7, 4);
44  // Create a second trace of Boolean values
45  QueueSource source_bool = new QueueSource();
46  source_bool.setEvents(true, false, true, true,
47  false, false, true, false, true);
48  // Create a filter
49  Filter filter = new Filter();
50  // Connect both to the filter
51  connect(source_values, OUTPUT, filter, TOP);
52  connect(source_bool, OUTPUT, filter, BOTTOM);
53  // Get a reference to the filter's output pullable
54  Pullable p = filter.getPullableOutput();
55  // Pull 5 events from p
56  for (int i = 0; i < 5; i++)
57  {
58  int x = (Integer) p.pull();
59  System.out.printf("Output event #%d is %d\n", i, x);
60  }
61  ///
62  }
63 
64 }
Discard events from an input trace with the Filter processor.
static void main(String[] args)