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