Code Examples
A repository of 155 code examples for BeepBeep
Nested.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 ltl;
19 
20 import static ca.uqac.lif.cep.Connector.BOTTOM;
21 import static ca.uqac.lif.cep.Connector.INPUT;
22 import static ca.uqac.lif.cep.Connector.TOP;
23 import static ca.uqac.lif.cep.Connector.OUTPUT;
24 
25 import ca.uqac.lif.cep.Connector;
26 import ca.uqac.lif.cep.Pushable;
27 import ca.uqac.lif.cep.functions.ApplyFunction;
28 import ca.uqac.lif.cep.functions.ApplyFunctionPartial;
29 import ca.uqac.lif.cep.functions.Constant;
30 import ca.uqac.lif.cep.functions.FunctionTree;
31 import ca.uqac.lif.cep.functions.StreamVariable;
32 import ca.uqac.lif.cep.io.Print;
33 import ca.uqac.lif.cep.ltl.Next;
34 import ca.uqac.lif.cep.ltl.Until;
35 import ca.uqac.lif.cep.tmf.Fork;
36 import ca.uqac.lif.cep.util.Booleans;
37 import ca.uqac.lif.cep.util.Equals;
38 
39 /**
40  * Basic usage of LTL's {@link Until} processor. It is illustrated
41  * as follows:
42  * <p>
43  * <img src="./doc-files/ltl/Nested.png" alt="Processor graph">
44  * <p>
45  * @author Sylvain HallĂ©
46  */
47 public class Nested
48 {
49  public static void main(String[] args)
50  {
51  Fork fork = new Fork(5);
52  ApplyFunctionPartial imp = new ApplyFunctionPartial(new FunctionTree(Booleans.implies,
53  new FunctionTree(Equals.instance, StreamVariable.X, new Constant("a")),
54  StreamVariable.Y
55  ));
56  Connector.connect(fork, 1, imp, TOP);
57  ApplyFunction f_nbc = new ApplyFunction(new FunctionTree(Booleans.not,
58  new FunctionTree(Booleans.and,
59  new FunctionTree(Equals.instance, StreamVariable.X, new Constant("b")),
60  StreamVariable.Y)));
61  Connector.connect(fork, 2, f_nbc, TOP);
62  ApplyFunction f_c = new ApplyFunction(
63  new FunctionTree(Equals.instance, StreamVariable.X, new Constant("c")));
64  Connector.connect(fork, 3, f_c, INPUT);
65  Next next = new Next();
66  Connector.connect(f_c, next);
67  Connector.connect(next, OUTPUT, f_nbc, BOTTOM);
68  Until until = new Until();
69  Connector.connect(f_nbc, OUTPUT, until, TOP);
70  ApplyFunction f_d = new ApplyFunction(
71  new FunctionTree(Equals.instance, StreamVariable.X, new Constant("d")));
72  Connector.connect(fork, 4, f_d, INPUT);
73  Connector.connect(f_d, OUTPUT, until, BOTTOM);
74  Connector.connect(until, OUTPUT, imp, BOTTOM);
75  Print print_out = new Print().setPrefix("Output: ").setSeparator("\n");
76  Connector.connect(imp, print_out);
77  Print print_in = new Print().setPrefix("Pushing: ").setSeparator("\n");
78  Connector.connect(fork, 0, print_in, INPUT);
79  Pushable p = fork.getPushableInput();
80  p.push("c");
81  p.push("d");
82  p.push("a");
83  p.push("c");
84  p.push("b");
85  p.push("d");
86  p.push("f");
87  ///
88  }
89 }
Basic usage of LTL&#39;s Until processor.
Definition: Nested.java:47