Code Examples
A repository of 155 code examples for BeepBeep
PressureEvent.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 episodes;
19 
20 import ca.uqac.lif.cep.functions.UnaryFunction;
21 
22 /**
23  * Abstract class representing events in a pressure stream
24  */
25 public abstract class PressureEvent
26 {
27  /**
28  * Static reference to a "new day" event
29  */
30  public static final NewDay NEW_DAY = new NewDay();
31 
32  /**
33  * Static reference to an "episode start" event
34  */
35  public static final EpisodeStart EPISODE_START = new EpisodeStart();
36 
37  /**
38  * Static reference to an "episode end" event
39  */
40  public static final EpisodeEnd EPISODE_END = new EpisodeEnd();
41 
42  /**
43  * Event representing the start of a new day
44  */
45  public static class NewDay extends PressureEvent
46  {
47  @Override
48  public String toString()
49  {
50  return "\u2737";
51  }
52  }
53 
54  /**
55  * Event representing the start of an episode
56  */
57  public static class EpisodeStart extends PressureEvent
58  {
59  @Override
60  public String toString()
61  {
62  return "\u2191";
63  }
64  }
65 
66  /**
67  * Event representing the end of an episode
68  */
69  public static class EpisodeEnd extends PressureEvent
70  {
71  @Override
72  public String toString()
73  {
74  return "\u2193";
75  }
76  }
77 
78  /**
79  * Event containing a pressure reading
80  */
81  public static class Reading extends PressureEvent
82  {
83  /**
84  * The value in this event
85  */
86  protected final int m_value;
87 
88  /**
89  * Creates a new reading event
90  * @param value The value in this event
91  */
92  public Reading(int value)
93  {
94  super();
95  m_value = value;
96  }
97 
98  @Override
99  public String toString()
100  {
101  return Integer.toString(m_value);
102  }
103 
104  /**
105  * Gets the value in this event
106  * @return The value
107  */
108  public int getValue()
109  {
110  return m_value;
111  }
112  }
113 
114  /**
115  * BeepBeep function checking if an event is an instance of
116  * "new day"
117  */
118  public static class IsNewDay extends UnaryFunction<PressureEvent,Boolean>
119  {
120  /**
121  * A public reference to a single instance of the function
122  */
123  public static transient final IsNewDay instance = new IsNewDay();
124 
125  protected IsNewDay()
126  {
127  super(PressureEvent.class, Boolean.class);
128  }
129 
130  @Override
131  public Boolean getValue(PressureEvent x)
132  {
133  return x instanceof NewDay;
134  }
135  }
136 
137  /**
138  * BeepBeep function checking if an event is an instance of
139  * reading
140  */
141  public static class IsReading extends UnaryFunction<PressureEvent,Boolean>
142  {
143  /**
144  * A public reference to a single instance of the function
145  */
146  public static transient final IsReading instance = new IsReading();
147 
148  protected IsReading()
149  {
150  super(PressureEvent.class, Boolean.class);
151  }
152 
153  @Override
154  public Boolean getValue(PressureEvent x)
155  {
156  return x instanceof Reading;
157  }
158  }
159 
160  /**
161  * BeepBeep function checking if an event is an instance of
162  * "episode start"
163  */
164  public static class IsEpisodeStart extends UnaryFunction<PressureEvent,Boolean>
165  {
166  /**
167  * A public reference to a single instance of the function
168  */
169  public static transient final IsEpisodeStart instance = new IsEpisodeStart();
170 
171  protected IsEpisodeStart()
172  {
173  super(PressureEvent.class, Boolean.class);
174  }
175 
176  @Override
177  public Boolean getValue(PressureEvent x)
178  {
179  return x instanceof EpisodeStart;
180  }
181  }
182 
183  /**
184  * BeepBeep function checking if an event is an instance of
185  * "episode end"
186  */
187  public static class IsEpisodeEnd extends UnaryFunction<PressureEvent,Boolean>
188  {
189  /**
190  * A public reference to a single instance of the function
191  */
192  public static transient final IsEpisodeEnd instance = new IsEpisodeEnd();
193 
194  protected IsEpisodeEnd()
195  {
196  super(PressureEvent.class, Boolean.class);
197  }
198 
199  @Override
200  public Boolean getValue(PressureEvent x)
201  {
202  return x instanceof EpisodeEnd;
203  }
204  }
205 
206  /**
207  * BeepBeep function checking if an event is an instance of
208  * "episode end"
209  */
210  public static class GetValue extends UnaryFunction<Reading,Number>
211  {
212  /**
213  * A public reference to a single instance of the function
214  */
215  public static transient final GetValue instance = new GetValue();
216 
217  protected GetValue()
218  {
219  super(Reading.class, Number.class);
220  }
221 
222  @Override
223  public Number getValue(Reading x)
224  {
225  return x.getValue();
226  }
227  }
228 
229 }
Abstract class representing events in a pressure stream.
static final EpisodeStart EPISODE_START
Static reference to an "episode start" event.
static final EpisodeEnd EPISODE_END
Static reference to an "episode end" event.
static final NewDay NEW_DAY
Static reference to a "new day" event.