-
Notifications
You must be signed in to change notification settings - Fork 0
/
OneEvent.java
executable file
·196 lines (177 loc) · 6.2 KB
/
OneEvent.java
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
// import java.util.TreeMap;
/*********************************************************************
* Class to handle a single event.
* It seems to be the case that doing this as a real class takes too
* much time and memory, so we are implementing this as static methods
* to return and extract from a single string variable.
*
* @author Duncan A. Buell
* Copyright (c) 2010-2012 Duncan A. Buell
*
* Permission is hereby granted, free of charge, to any person
* obtaining a copy of this software and associated documentation
* files (the "Software"), to deal in the Software without
* restriction, including without limitation the rights to use,
* copy, modify, merge, publish, distribute, sublicense, and/or sell
* copies of the Software, and to permit persons to whom the
* Software is furnished to do so, subject to the following
* conditions:
*
* The above copyright notice and this permission notice shall be
* included in all copies or substantial portions of the Software.
*
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES
* OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
* NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
* HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY,
* WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
* FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
* OTHER DEALINGS IN THE SOFTWARE.
**/
public class OneEvent
{
/*********************************************************************
* Instance variables for the class.
**/
// static private final String TAG = "OneEvent: "; // for testing
/*********************************************************************
* Accessors and mutators.
**/
/*********************************************************************
* Accessor for <code>code</code>.
*
* @return the value of <code>code</code>
**/
static public String getCode(String eventString)
{
int START = 44;
int END = 51;
return eventString.substring(START, END);
} // public String getCode()
/*********************************************************************
* Accessor for <code>date</code>.
*
* @return the value of <code>date</code>
**/
static public String getDate(String eventString)
{
int START = 22;
int END = 32;
return eventString.substring(START, END);
} // public String getDate()
/*********************************************************************
* Accessor for <code>date</code> and <code>time</code> together.
*
* @return the value of <code>date</code> concat with <code>time</code>
**/
static public String getDateAndTime(String eventString)
{
int START = 22;
int END = 41;
return eventString.substring(START, END);
} // static public String getDateAndTime(String eventString)
/*********************************************************************
* Accessor for <code>ivoNumber</code>.
*
* @return the value of <code>ivoNumber</code>
**/
static public String getIvoNumber(String eventString)
{
int START = 0;
int END = 7;
return eventString.substring(START, END);
} // public String getIvoNumber()
/*********************************************************************
* Accessor for <code>pebNumber</code>.
*
* @return the value of <code>pebNumber</code>
**/
static public String getPebNumber(String eventString)
{
int START = 8;
int END = 15;
return eventString.substring(START, END);
} // public String getPebNumber()
/*********************************************************************
* Accessor for <code>time</code>.
*
* @return the value of <code>time</code>
**/
static public String getTime(String eventString)
{
int START = 33;
int END = 41;
return eventString.substring(START, END);
} // public String getTime()
/*********************************************************************
* Accessor for <code>type</code>.
*
* @return the value of <code>type</code>
**/
static public String getType(String eventString)
{
int START = 16;
int END = 19;
// FileUtils.logFile.printf("TYPE X%sX%n",
// eventString.substring(START, END));
return eventString.substring(START, END);
} // public String getType()
/*********************************************************************
* General methods.
**/
/*********************************************************************
* Method to make an event string from a 152 line.
**/
static public String makeEventString(String ivo, String peb, String line)
{
String ivoNumber;
String pebNumber;
String code;
String date;
String time;
String type;
String year, month, day;
String hour, minute, second;
String s;
ivoNumber = line.substring( 0, 7);
if(ivoNumber.equals(" "))
{
ivoNumber = ivo;
}
pebNumber = line.substring( 8,15);
if(pebNumber.trim().equals(""))
{
pebNumber = peb;
}
type = line.substring(17,20);
date = line.substring(23,33);
time = line.substring(34,42);
code = line.substring(45,52);
year = date.substring(6);
month = date.substring(0, 2);
day = date.substring(3, 5);
if((Integer.valueOf(month.trim()) < 0) || (Integer.valueOf(month.trim()) > 12))
{
FileUtils.logFile.printf("BAD MONTH %s: %s%n", month, line);
FileUtils.logFile.flush();
}
if((Integer.valueOf(day.trim()) < 0) || (Integer.valueOf(day.trim()) > 31))
{
FileUtils.logFile.printf("BAD DAY %s: %s%n", day, line);
FileUtils.logFile.flush();
}
hour = time.substring(0, 2);
minute = time.substring(3, 5);
second = time.substring(6, 8);
s = String.format("%7s %7s %3s %4s_%2s_%2s %2s:%2s:%2s %7s",
ivoNumber, pebNumber, type,
year, month, day,
hour, minute, second, code);
// FileUtils.logFile.printf("ZORK X%sX X%sX X%sX X%sX X%sX X%sX X%sX X%sX X%sX X%sX%n",
// ivoNumber, pebNumber, type,
// year, month, day,
// hour, minute, second, code);
return s;
} // static public makeEventString(String ivo, String peb, String line)
} // public class Event