1 19 20 package za.org.coefficient.modules.vote; 21 22 import za.org.coefficient.authentication.Role; 23 24 import java.util.ArrayList ; 25 import java.util.Date ; 26 import java.util.GregorianCalendar ; 27 import java.util.List ; 28 29 33 public class VoteData implements java.io.Serializable { 34 36 static String [] months = 37 { 38 "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", 39 "Nov", "Dec" 40 }; 41 42 44 private Boolean status; 45 private Date endDate; private Date startDate; private List answers = new ArrayList (); 48 private List counts = new ArrayList (); 49 private List voters = new ArrayList (); 50 private Long id; private Long projectId; private Long sequence; private Role minimumRole; private String name; 55 private String person; 56 private String question; 57 58 60 public VoteData() { 61 name = new String (); 62 question = new String (); 63 status = new Boolean (true); 64 } 65 66 68 public static String getDay(Date date) { 69 try { 70 GregorianCalendar gc = new GregorianCalendar (); 71 gc.setTime(date); 72 String st = new String ("" + gc.get(gc.DATE)); 73 74 return st; 75 } catch (Throwable t) { 76 return "bad date!"; 77 } 78 } 79 80 85 public void setAnswers(List answers) { 86 this.answers = answers; 87 } 88 89 104 public List getAnswers() { 105 return this.answers; 106 } 107 108 113 public void setCounts(List counts) { 114 this.counts = counts; 115 } 116 117 132 public List getCounts() { 133 return this.counts; 134 } 135 136 public void setEndDate(String year, String month, String day) { 137 endDate = setDate(year, month, day); 138 } 139 140 145 public void setEndDate(Date argEndDate) { 146 this.endDate = argEndDate; 147 } 148 149 156 public Date getEndDate() { 157 return this.endDate; 158 } 159 160 public String getEndDateAsString() { 161 return getDate(endDate); 162 } 163 164 public String getEndDateYear() { 165 return getYear(endDate); 166 } 167 168 173 public void setId(Long argId) { 174 this.id = argId; 175 } 176 177 184 public Long getId() { 185 return this.id; 186 } 187 188 public static String getMonth(Date date) { 189 try { 190 GregorianCalendar gc = new GregorianCalendar (); 191 gc.setTime(date); 192 String st = new String (months[gc.get(gc.MONTH)]); 193 194 return st; 195 } catch (Throwable t) { 196 return "bad date!"; 197 } 198 } 199 200 public void setMinimumRole(Role argRole) { 201 this.minimumRole = argRole; 202 } 203 204 211 public Role getMinimumRole() { 212 return this.minimumRole; 213 } 214 215 220 public void setName(String name) { 221 this.name = name; 222 } 223 224 231 public String getName() { 232 return this.name; 233 } 234 235 240 public void setPerson(String person) { 241 this.person = person; 242 } 243 244 251 public String getPerson() { 252 return this.person; 253 } 254 255 260 public void setProjectId(Long argId) { 261 this.projectId = argId; 262 } 263 264 271 public Long getProjectId() { 272 return this.projectId; 273 } 274 275 280 public void setQuestion(String question) { 281 this.question = question; 282 } 283 284 292 public String getQuestion() { 293 return this.question; 294 } 295 296 301 public void setSequence(Long argSequence) { 302 this.sequence = argSequence; 303 } 304 305 public void setSequence(String argSequence) { 306 try { 307 this.sequence = new Long (argSequence); 308 } catch (Throwable t) { 309 System.out.println("illegal sequence number"); 310 } 311 } 312 313 320 public Long getSequence() { 321 return this.sequence; 322 } 323 324 329 public void setStartDate(Date argStartDate) { 330 this.startDate = argStartDate; 331 } 332 333 public void setStartDate(String year, String month, String day) { 334 startDate = setDate(year, month, day); 335 } 336 337 344 public Date getStartDate() { 345 return this.startDate; 346 } 347 348 public static String getYear(Date date) { 349 try { 350 GregorianCalendar gc = new GregorianCalendar (); 351 gc.setTime(date); 352 String st = new String ("" + gc.get(gc.YEAR)); 353 354 return st; 355 } catch (Throwable t) { 356 return "bad date!"; 357 } 358 } 359 360 public String getEndDateDay() { 361 return getDay(endDate); 362 } 363 364 public String getEndDateMonth() { 365 return getMonth(endDate); 366 } 367 368 public String getStartDateAsString() { 369 return getDate(startDate); 370 } 371 372 public String getStartDateDay() { 373 return getDay(startDate); 374 } 375 376 public String getStartDateMonth() { 377 return getMonth(startDate); 378 } 379 380 public String getStartDateYear() { 381 return getYear(startDate); 382 } 383 384 389 public void setStatus(Boolean status) { 390 this.status = status; 391 } 392 393 400 public Boolean getStatus() { 401 return this.status; 402 } 403 404 409 public void setVoters(List voters) { 410 this.voters = voters; 411 } 412 413 428 public List getVoters() { 429 return this.voters; 430 } 431 432 public String dump() { 433 String st = 434 new String ("\nID " + id + "\n" + "PROJECTID " + projectId + "\n" 435 + "NAME " + name + "\n" + "PERSON " + person + "\n" 436 + "QUESTION " + question + "\n" + "START " + startDate + "\n" 437 + "END " + endDate + "\n" + "STATUS " + status + "\n" 438 + "ANSWERS " + answers + "\n" + "COUNTS " + counts + "\n" 439 + "ROLE " + minimumRole + "\n"); 440 441 return st; 442 } 443 444 private Date setDate(String year, String month, String day) { 445 int i; 446 int intYear; 447 int intMonth; 448 int intDay; 449 450 try { 451 intYear = Integer.parseInt(year); 452 } catch (Throwable t) { 453 intYear = 1900; 454 } 455 456 try { 457 intDay = Integer.parseInt(day); 458 } catch (Throwable t) { 459 intDay = 1; 460 } 461 462 intMonth = 0; 463 for (i = 0; i < months.length; i++) { 464 if (month.equals(months[i])) { 465 intMonth = i; 466 467 break; 468 } 469 } 470 471 GregorianCalendar gc = new GregorianCalendar (intYear, intMonth, intDay); 472 473 return gc.getTime(); 474 } 475 476 private String getDate(Date date) { 477 try { 478 GregorianCalendar gc = new GregorianCalendar (); 479 gc.setTime(date); 480 String st = 481 new String (gc.get(gc.DAY_OF_MONTH) + " " 482 + months[gc.get(gc.MONTH)] + " " + gc.get(gc.YEAR)); 483 484 return st; 485 } catch (Throwable t) { 486 return "bad date!"; 487 } 488 } 489 } 490 | Popular Tags |