-
Notifications
You must be signed in to change notification settings - Fork 0
/
OnePrecinct.java
executable file
·351 lines (313 loc) · 9.91 KB
/
OnePrecinct.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
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
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
import java.util.TreeMap;
/*********************************************************************
* Class to handle a single instance of precinct data.
*
* @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 OnePrecinct
{
/*********************************************************************
* Instance variables for the class.
**/
// private static final String TAG = "OnePrecinct: "; // for testing
private int voters;
private int votes155;
private int votesCast;
private String turnout;
private String pctNumber;
private String name;
private TreeMap<String, String> closePEBs;
private TreeMap<String, String> openPEBs;
private TreeMap<String, String> terminals;
/*********************************************************************
* Constructor.
**/
public OnePrecinct()
{
this.pctNumber = Globals.convertToPctNumber(0);
this.voters = Globals.DUMMYINT;
this.votes155 = Globals.DUMMYINT;
this.votesCast = Globals.DUMMYINT;
this.turnout = Globals.DUMMYSTRING;
this.name = Globals.DUMMYSTRING;
closePEBs = new TreeMap<String, String>();
openPEBs = new TreeMap<String, String>();
terminals = new TreeMap<String, String>();
} // public OnePrecinct()
/*********************************************************************
* Constructor.
**/
public OnePrecinct(String line, int break1, int break2, int break3)
{
this.name = line.substring(0,break1).trim().toUpperCase();
this.name = Constants.filterPctName(this.name);
// FileUtils.logFile.printf("%s NAME Y%sY%n", TAG, this.name);
// FileUtils.logFile.flush();
if(this.name.equals("ABSENTEE"))
{
this.name = "ABSENTEE";
}
if(this.name.equals("EMERGENCY"))
{
this.name = "EMERGENCY";
}
if(this.name.equals("FAILSAFE"))
{
this.name = "FAILSAFE";
}
if(this.name.equals("FAILSAFE_PROVISIONAL"))
{
this.name = "FAILSAFE_PROVISIONAL";
}
if(this.name.equals("PROVISIONAL"))
{
this.name = "PROVISIONAL";
}
if(this.name.equals("TOTAL:"))
{
this.name = "TOTAL";
}
this.voters = Integer.valueOf(line.substring(break1,break2).trim());
this.votes155 = Globals.DUMMYINT;
this.votesCast = Integer.valueOf(line.substring(break2,break3).trim());
this.turnout = line.substring(break3).trim();
closePEBs = new TreeMap<String, String>();
openPEBs = new TreeMap<String, String>();
terminals = new TreeMap<String, String>();
} // public OnePrecinct()
/*********************************************************************
* Accessors and mutators.
**/
/*********************************************************************
* Accessor for the size of <code>getClosePEBs</code>.
*
* @return the size of <code>getClosePEBs</code>
**/
public int getClosePEBSize()
{
return this.closePEBs.size();
} // public int getClosePEBSize()
/*********************************************************************
* Accessor for <code>name</code>.
*
* @return the value of <code>name</code>
**/
public String getPctName()
{
return this.name;
} // public String getPctName()
/*********************************************************************
* Accessor for <code>pctNumber</code>.
*
* @return the value of <code>pctNumber</code>
**/
public String getPctNumber()
{
return this.pctNumber;
} // public String getPctNumber()
/*********************************************************************
* Mutator for <code>pctNumber</code>.
*
* @param the value of <code>pctNumber</code>
**/
public void setPctNumber(String what)
{
this.pctNumber = Globals.convertToPctNumber(what);
// FileUtils.logFile.printf("SET PRECINCT X%sX%n", this.pctNumber);
} // public void setPctNumber(String what)
/*********************************************************************
* Accessor for <code>terminals</code>.
*
* @return the value of <code>terminals</code>
**/
public TreeMap<String, String> getTerminals()
{
return this.terminals;
} // public TreeMap<String, String> getTerminals()
/*********************************************************************
* Accessor for <code>voters</code>.
*
* @return the value of <code>voters</code>
**/
public int getVoters()
{
return this.voters;
} // public int getVoters()
/*********************************************************************
* Accessor for <code>votes155</code>.
*
* @return the value of <code>votes155</code>
**/
public int getVotes155()
{
return this.votes155;
} // public int getVotes155()
/*********************************************************************
* Mutator for <code>votes155</code>.
*
* @parm the value of <code>votes155</code> to set
**/
public void setVotes155(int howMany)
{
// FileUtils.logFile.printf("set155 %s %s %d%n", this.pctNumber, this.name, howMany);
this.votes155 = howMany;
} // public void setVotes155(int howMany)
/*********************************************************************
* Accessor for <code>votesCast</code>.
*
* @return the value of <code>votesCast</code>
**/
public int getVotesCast()
{
return this.votesCast;
} // public int getVotesCast()
/*********************************************************************
* Accessor for <code>turnout</code>.
*
* @return the value of <code>turnout</code>
**/
public String getTurnout()
{
return this.turnout;
} // public String getTurnout()
/*********************************************************************
* Accessor for the <code>name</code>.
*
* @return the value of <code>name</code>.
**/
public String getName()
{
return this.name;
} // public String getName()
/*********************************************************************
* General methods.
**/
/*********************************************************************
* Method to set a closing peb number for this pct.
*
* @param the peb number to set
**/
public void setClosePEB(String peb)
{
this.closePEBs.put(peb, peb);
} // public void setClosePEB(String peb)
/*********************************************************************
* Method to set an opening peb number for this pct.
*
* @param the peb number to set
**/
public void setOpenPEB(String peb)
{
this.openPEBs.put(peb, peb);
} // public void setOpenPEB(String peb)
/*********************************************************************
* Method to set a terminal number for this pct.
*
* @param the terminal number to set
**/
public void setTerm(String term)
{
this.terminals.put(term, term);
} // public void setTerm(String term)
/*********************************************************************
* Method to convert a <code>OnePrecinct</code> to a
* <code>String</code>.
*
* @return the formatted <code>String</code> value.
**/
public String toString()
{
String s = "";
s += String.format(" %4s", this.pctNumber);
s += String.format(" %-30s", this.name);
s += String.format(" %8s", Globals.convertToGoodVoteNumber(this.voters));
s += String.format(" %8s", Globals.convertToGoodVoteNumber(this.votesCast));
s += String.format(" %8s", this.turnout);
s += String.format(" (");
for(String term: this.terminals.keySet())
{
s += String.format(" %7s", term);
}
s += String.format(")");
s += String.format(" (");
for(String peb: this.openPEBs.keySet())
{
s += String.format(" %7s", peb);
}
s += String.format(")");
s += String.format(" (");
for(String peb: this.closePEBs.keySet())
{
s += String.format(" %7s", peb);
}
s += String.format(")");
return s;
} // public String toString()
/*********************************************************************
* Method to <code>toString</code> <code>closePEBs</code>.
*
* @return the expected string
**/
public String toStringClosePEBs()
{
String s = String.format(" (");
for(String peb: this.closePEBs.keySet())
{
s += String.format(" %7s", peb);
}
s += String.format(")");
return s;
} // public String toStringClosePEBs()
/*********************************************************************
* Method to <code>toString</code> <code>openPEBs</code>.
*
* @return the expected string
**/
public String toStringOpenPEBs()
{
String s = String.format(" (");
for(String peb: this.openPEBs.keySet())
{
s += String.format(" %7s", peb);
}
s += String.format(")");
return s;
} // public String toStringOpenPEBs()
/*********************************************************************
* Method to <code>toString</code> the <code>terminals</code>.
*
* @return the expected string
**/
public String toStringTerminals()
{
String s = String.format(" (");
for(String term: this.terminals.keySet())
{
s += String.format(" %7s", term);
}
s += String.format(")");
return s;
} // public String toStringTerminals()
} // public class OnePrecinct