-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathRTMLScore.java
More file actions
229 lines (210 loc) · 5.72 KB
/
RTMLScore.java
File metadata and controls
229 lines (210 loc) · 5.72 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
/*
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
*/
// RTMLScore.java
// $Header: /space/home/eng/cjm/cvs/org_estar_rtml/RTMLScore.java,v 1.2 2008-05-27 14:58:25 cjm Exp $
package org.estar.rtml;
import java.io.*;
import java.text.*;
import java.util.*;
/**
* This class is a data container for information contained in the Score tags of an RTML document.
* @author Chris Mottram
* @version $Revision$
*/
public class RTMLScore implements Serializable
{
/**
* Revision control system version id.
*/
public final static String RCSID = "$Id$";
/**
* Serial version ID. Fixed as these documents can be used as parameters in RMI calls across JVMs.
*/
static final long serialVersionUID = 6600424686842633408L;
/**
* The delay attribute specified in the score, can be null.
* @see RTMLPeriodFormat
*/
protected RTMLPeriodFormat delay = null;
/**
* The probability attribute specified in the score, only used if delay is non-null.
* Can be NaN.
* @see #delay
*/
protected double probability = 0.0;
/**
* The cumulative probability attribute specified in the score, only used if delay is non-null.
* Can be NaN.
* @see #delay
*/
protected double cumulative = 0.0;
/**
* Score 'value', used as tag CDATA if delay _is_ null.
* @see #delay
*/
protected double score = 0.0;
/**
* Default constructor.
*/
public RTMLScore()
{
super();
}
/**
* Set the score to be a simple number. The delay is set to null by this method.
* @param s The score, a double normally between 0 and 1.
* @see #score
* @see #delay
*/
public void setScore(double s)
{
score = s;
delay = null;
}
/**
* Get the score parameter. Only really use if isSimple returns true.
* @return The score, a double normally between 0 and 1.
* @see #score
*/
public double getScore()
{
return score;
}
/**
* Get whether the RTML Score is "simple" (a single double CDATA between 0 and 1),
* or not (contains delay, probability and cumulative attributes and no CDATA).
* @return Returns a boolean, true if the score is "simple".
*/
public boolean isSimple()
{
return (delay == null);
}
/**
* Set the delay. If null, this score will be "simple".
* @param pf The delay, an instance of RTMLPeriodFormat. This can be null,
* if we wish this score to be "simple".
* @see #delay
* @see #isSimple
* @see RTMLPeriodFormat
*/
public void setDelay(RTMLPeriodFormat pf)
{
delay = pf;
}
/**
* Get the delay.
* @return The delay. This can be null if the Score is "simple"
* @see #delay
* @see #isSimple
*/
public RTMLPeriodFormat getDelay()
{
return delay;
}
/**
* Set the probability. This will be used only if delay is _not_ null,
* @param p The probability, a number between 0 and 1 or NaN.
* @see #probability
* @see #isSimple
* @see java.lang.Double#NaN
*/
public void setProbability(double p)
{
probability = p;
}
/**
* Get the probability. This will be used only if delay is _not_ null,
* @return The probability, a number between 0 and 1 or NaN.
* @see #probability
* @see #isSimple
* @see java.lang.Double#NaN
*/
public double getProbability()
{
return probability;
}
/**
* Set the cumulative probability. This will be used only if delay is _not_ null,
* @param p The cumulative probability, a number between 0 and 1 or NaN.
* @see #cumulative
* @see #isSimple
* @see java.lang.Double#NaN
*/
public void setCumulative(double p)
{
cumulative = p;
}
/**
* Get the cumulative probability. This will be used only if delay is _not_ null,
* @return The cumulative probability, a number between 0 and 1 or NaN.
* @see #probability
* @see #isSimple
* @see java.lang.Double#NaN
*/
public double getCumulative()
{
return cumulative;
}
/**
* Method to print out a string representation of this node.
* @return A string representation of this object.
* @see #toString(java.lang.String)
*/
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.
* @return A string representation of this object.
* @see #score
* @see #delay
* @see #probability
* @see #cumulative
* @see #isSimple
*/
public String toString(String prefix)
{
DecimalFormat df = null;
StringBuffer sb = null;
df = new DecimalFormat("0.0#");
sb = new StringBuffer();
sb.append(prefix+"Score:");
if(isSimple())
sb.append(" "+df.format(score)+"\n");
else
{
sb.append(" Delay: "+delay.toString());
if(Double.isNaN(probability))
sb.append(" Probability: NaN");
else
sb.append(" Probability: "+df.format(probability));
if(Double.isNaN(cumulative))
sb.append(" Cumulative: NaN");
else
sb.append(" Cumulative: "+df.format(cumulative));
sb.append("\n");
}
return sb.toString();
}
}
/*
** $Log: not supported by cvs2svn $
** Revision 1.1 2007/03/27 19:15:01 cjm
** Initial revision
**
*/