Code Examples
A repository of 155 code examples for BeepBeep
SnapshotQuery.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 stockticker;
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.ApplyFunction;
24 import ca.uqac.lif.cep.functions.Constant;
25 import ca.uqac.lif.cep.functions.FunctionTree;
26 import ca.uqac.lif.cep.tmf.Filter;
27 import ca.uqac.lif.cep.tmf.Fork;
28 import ca.uqac.lif.cep.tmf.Prefix;
29 import ca.uqac.lif.cep.util.Equals;
30 import ca.uqac.lif.cep.util.NthElement;
31 
32 public class SnapshotQuery
33 {
34  public static void main(String[] args)
35  {
36  ///
37  TickerFeed feed = new TickerFeed();
38  Fork fork = new Fork(2);
39  Connector.connect(feed, fork);
40  Filter filter = new Filter();
41  Connector.connect(fork, 0, filter, 0);
42  ApplyFunction is_msft = new ApplyFunction(
43  new FunctionTree(Equals.instance,
44  new Constant("MSFT"),
45  new NthElement(1)));
46  Connector.connect(fork, 1, is_msft, 0);
47  Connector.connect(is_msft, 0, filter, 1);
48  Prefix pref = new Prefix(5);
49  Connector.connect(filter, pref);
50  ///
51  Pullable p = pref.getPullableOutput();
52  while (p.hasNext())
53  {
54  System.out.println(UtilityMethods.print(p.pull()));
55  }
56  }
57 }