Code Examples
A repository of 155 code examples for BeepBeep
ConstantUsage.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 functions;
19 
20 import ca.uqac.lif.cep.functions.Constant;
21 import ca.uqac.lif.cep.functions.Function;
22 import ca.uqac.lif.cep.functions.FunctionException;
23 
24 /**
25  * Basic usage of the {@link ca.uqac.lif.cep.functions.Constant}
26  * function.
27  * @author Sylvain HallĂ©
28  */
29 public class ConstantUsage
30 {
31  public static void main(String[] args) throws FunctionException
32  {
33  /* Create a new function that will return the same thing,
34  * whatever its arguments. This is done by instantiating a Constant
35  * object. The constructor of this class takes as input the object
36  * that will be the return value of the function. Here, our constant
37  * function will always return the string "foo". */
38  Function foo = new Constant("foo");
39 
40  /* A constant does not need any argument; we may pass
41  * an empty array, or simply null. */
42  Object[] values = new Object[1];
43  foo.evaluate(null, values);
44  String s_value = (String) values[0]; // = "foo"
45  System.out.printf("The value of foo is %s\n", s_value);
46 
47  /* Let's create another constant function, this time returning the
48  * number 1 every time it is called. */
49  Function one = new Constant(1);
50  one.evaluate(null, values);
51  int i_value = (Integer) values[0]; // = 1
52  System.out.printf("The value of one is %d\n", i_value);
53  }
54 }
Basic usage of the ca.uqac.lif.cep.functions.Constant function.