-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRTMLSeriesConstraint.java
More file actions
261 lines (239 loc) · 6.37 KB
/
RTMLSeriesConstraint.java
File metadata and controls
261 lines (239 loc) · 6.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
/*
Copyright 2006, Astrophysics Research Institute, Liverpool John Moores University.
This file is part of org.estar.rtml.
org.estar.rtml is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2 of the License, or
(at your option) any later version.
org.estar.rtml is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with org.estar.rtml; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
// RTMLSeriesConstraint.java
// $Header: /space/home/eng/cjm/cvs/org_estar_rtml/RTMLSeriesConstraint.java,v 1.6 2008-08-11 13:54:54 cjm Exp $
package org.estar.rtml;
import java.io.*;
import java.text.*;
/**
* This class is a data container for information contained in the SeriesConstraint nodes/tags of an RTML document.
* There are three main elements in a SeriesConstraint:
* <ul>
* <li><b>count</b>
* <li><b>interval</b>
* <li><b>tolerance</b>
* </ul>
* The SeriesConstraint constrains it's associated observation in the following manner:
* <i>Do the observation <b>count</b> times with a time period of <b>interval</b>
* +/- <b>tolerance</b> between them.</i>
* @author Chris Mottram
* @version $Revision$
*/
public class RTMLSeriesConstraint implements Serializable
{
/**
* Revision control system version id.
*/
public final static String RCSID = "$Id$";
/**
* The number of times the observation associated wit this SeriesConstraint should be executed.
*/
private int count = 0;
/**
* The interval between doing each observation.
*/
private RTMLPeriodFormat interval = null;
/**
* The slack in the interval between doing each observation.e.g.
* Do the observation count times with a time period of interval +/- tolerance between them.
*/
private RTMLPeriodFormat tolerance = null;
/**
* Default constructor.
*/
public RTMLSeriesConstraint()
{
super();
}
/**
* Set the count
* @param s The count, specified as a string representation of an integer.
* @see #count
*/
public void setCount(String s) throws NumberFormatException
{
count = Integer.parseInt(s);
}
/**
* Set the count.
* @param i An integer.
* @see #count
*/
public void setCount(int i)
{
count = i;
}
/**
* Get the count.
* @return The count.
* @see #count
*/
public int getCount()
{
return count;
}
/**
* Set the interval.
* @param p An interval.
* @see #interval
*/
public void setInterval(RTMLPeriodFormat p)
{
interval = p;
}
/**
* Set the interval
* @param s A string, in the format P{(yyyy)Y{(mm)M}{(dd)D}{T{(hh)H}{(mm}M}{(ss.s..)S}.
* @see #interval
* @exception RTMLException Thrown if the string is not a valid period,
* using the format specified above.
* @see #interval
*/
public void setInterval(String s) throws RTMLException
{
interval = new RTMLPeriodFormat();
try
{
interval.parse(s);
}
catch(RTMLException e)
{
throw new RTMLException(this.getClass().getName()+":setInterval:Illegal Period:"+s+":",e);
}
}
/**
* Get the interval
* @return An interval.
* @see #interval
*/
public RTMLPeriodFormat getInterval()
{
return interval;
}
/**
* Set the tolerance.
* @param p An tolerance.
* @see #tolerance
*/
public void setTolerance(RTMLPeriodFormat p)
{
tolerance = p;
}
/**
* Set the tolerance.
* @param s A string, in the format P{(yyyy)Y{(mm)M}{(dd)D}{T{(hh)H}{(mm}M}{(ss.s..)S}.
* @see #tolerance
* @exception RTMLException Thrown if the string is not a valid period,
* using the format specified above.
* @see #tolerance
*/
public void setTolerance(String s) throws RTMLException
{
tolerance = new RTMLPeriodFormat();
try
{
tolerance.parse(s);
}
catch(RTMLException e)
{
throw new RTMLException(this.getClass().getName()+":setTolerance:Illegal Period:"+s+":",e);
}
}
/**
* Get the tolerance
* @return An tolerance.
* @see #tolerance
*/
public RTMLPeriodFormat getTolerance()
{
return tolerance;
}
/**
* Test whether one series constraint is equal to another.
* @param obj The other instance we are testing against.
* @return Returns true if the contents are the same, and false if they are not.
* @see #count
* @see #interval
* @see #tolerance
* @see org.estar.rtml.RTMLPeriodFormat#equals
*/
public boolean equals(Object obj)
{
RTMLSeriesConstraint otherSC = null;
if(obj == null)
return false;
if((obj instanceof RTMLSeriesConstraint) == false)
{
return false;
}
otherSC = (RTMLSeriesConstraint)obj;
if(otherSC.getCount() != count)
return false;
if(otherSC.getInterval() == null)
return false;
if(otherSC.getInterval().equals(interval) == false)
return false;
if(otherSC.getTolerance() == null)
return false;
if(otherSC.getTolerance().equals(tolerance) == false)
return false;
return true;
}
/**
* Method to print out a string representation of this node.
*/
public String toString()
{
return toString("");
}
/**
* Method to print out a string representation of this node, with a prefix.
* @param prefix A string to prefix to each line of data we print out.
* @see #count
* @see #interval
* @see #tolerance
*/
public String toString(String prefix)
{
StringBuffer sb = null;
sb = new StringBuffer();
sb.append(prefix+"Series Constraint:\n");
sb.append(prefix+"\tCount:"+count+"\n");
if(interval != null)
sb.append(prefix+"\tInterval:"+interval+" : "+interval.getMilliseconds()+" ms.\n");
if(tolerance != null)
sb.append(prefix+"\tTolerance:"+tolerance+" : "+tolerance.getMilliseconds()+" ms.\n");
return sb.toString();
}
}
/*
** $Log: not supported by cvs2svn $
** Revision 1.5 2007/01/30 18:31:22 cjm
** gnuify: Added GNU General Public License.
**
** Revision 1.4 2005/04/28 09:23:27 cjm
** spell check fix.
**
** Revision 1.3 2005/04/27 15:41:56 cjm
** Fixed toString null reference problems with interval and tolerance.
**
** Revision 1.2 2005/04/27 15:40:05 cjm
** Fixed toString tabbing.
**
** Revision 1.1 2005/04/27 13:46:24 cjm
** Initial revision
**
*/