KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > za > org > coefficient > modules > vote > VoteData


1 /*
2  * Coefficient - facilitates project based collaboration
3  * Copyright (C) 2003, Dylan Etkin, CSIR icomtek
4  * PO Box 395
5  * Pretoria 0001, RSA
6  * This library is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  * This library is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with this library; if not, write to the Free Software
17  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18  */

19
20 package za.org.coefficient.modules.vote;
21
22 import za.org.coefficient.authentication.Role;
23
24 import java.util.ArrayList JavaDoc;
25 import java.util.Date JavaDoc;
26 import java.util.GregorianCalendar JavaDoc;
27 import java.util.List JavaDoc;
28
29 /**
30  * @hibernate.class
31  * table="COEFFICIENT_VOTE"
32  */

33 public class VoteData implements java.io.Serializable JavaDoc {
34     //~ Static fields/initializers =============================================
35

36     static String JavaDoc[] months =
37     {
38         "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct",
39         "Nov", "Dec"
40     };
41
42     //~ Instance fields ========================================================
43

44     private Boolean JavaDoc status;
45     private Date JavaDoc endDate; // estimated finish date
46
private Date JavaDoc startDate; // date vote is scheduled to start
47
private List JavaDoc answers = new ArrayList JavaDoc();
48     private List JavaDoc counts = new ArrayList JavaDoc();
49     private List JavaDoc voters = new ArrayList JavaDoc();
50     private Long JavaDoc id; // unique to the file
51
private Long JavaDoc projectId; // projectId to which this belongs
52
private Long JavaDoc sequence; // sequence number unique to the project
53
private Role minimumRole; // minimum role for voting
54
private String JavaDoc name;
55     private String JavaDoc person;
56     private String JavaDoc question;
57
58     //~ Constructors ===========================================================
59

60     public VoteData() {
61         name = new String JavaDoc();
62         question = new String JavaDoc();
63         status = new Boolean JavaDoc(true);
64     }
65
66     //~ Methods ================================================================
67

68     public static String JavaDoc getDay(Date JavaDoc date) {
69         try {
70             GregorianCalendar JavaDoc gc = new GregorianCalendar JavaDoc();
71             gc.setTime(date);
72             String JavaDoc st = new String JavaDoc("" + gc.get(gc.DATE));
73
74             return st;
75         } catch (Throwable JavaDoc t) {
76             return "bad date!";
77         }
78     }
79
80     /**
81      * Sets the value of answers
82      *
83      * @param answers Value to assign to this.answers
84      */

85     public void setAnswers(List JavaDoc answers) {
86         this.answers = answers;
87     }
88
89     /**
90      * Gets the value of answers
91      *
92      * @return the value of answers
93      * @hibernate.list
94      * cascade="all"
95      * table="COEFFICIENT_VOTE_ANSWERS"
96      * @hibernate.collection-key
97      * column="PROJECT_ID"
98      * @hibernate.collection-index
99      * column="IDX"
100      * @hibernate.collection-element
101      * column="ANSWERS"
102      * type="string"
103      */

104     public List JavaDoc getAnswers() {
105         return this.answers;
106     }
107
108     /**
109      * Sets the value of counts
110      *
111      * @param counts Value to assign to this.counts
112      */

113     public void setCounts(List JavaDoc counts) {
114         this.counts = counts;
115     }
116
117     /**
118      * Gets the value of counts
119      *
120      * @return the value of counts
121      * @hibernate.list
122      * cascade="all"
123      * table="COEFFICIENT_VOTE_COUNTS"
124      * @hibernate.collection-key
125      * column="VOTE_ID"
126      * @hibernate.collection-index
127      * column="IDX"
128      * @hibernate.collection-element
129      * column="COUNTS"
130      * type="long"
131      */

132     public List JavaDoc getCounts() {
133         return this.counts;
134     }
135
136     public void setEndDate(String JavaDoc year, String JavaDoc month, String JavaDoc day) {
137         endDate = setDate(year, month, day);
138     }
139
140     /**
141      * Sets the value of endDate
142      *
143      * @param argId Value to assign to this.endDate
144      */

145     public void setEndDate(Date JavaDoc argEndDate) {
146         this.endDate = argEndDate;
147     }
148
149     /**
150      * Gets the value of endDate
151      *
152      * @return the value of endDate
153      * @hibernate.property
154      * column="END_DATE"
155      */

156     public Date JavaDoc getEndDate() {
157         return this.endDate;
158     }
159
160     public String JavaDoc getEndDateAsString() {
161         return getDate(endDate);
162     }
163
164     public String JavaDoc getEndDateYear() {
165         return getYear(endDate);
166     }
167
168     /**
169      * Sets the value of id
170      *
171      * @param argId Value to assign to this.id
172      */

173     public void setId(Long JavaDoc argId) {
174         this.id = argId;
175     }
176
177     /**
178      * Gets the value of id
179      *
180      * @return the value of id
181      * @hibernate.id
182      * generator-class="native"
183      */

184     public Long JavaDoc getId() {
185         return this.id;
186     }
187
188     public static String JavaDoc getMonth(Date JavaDoc date) {
189         try {
190             GregorianCalendar JavaDoc gc = new GregorianCalendar JavaDoc();
191             gc.setTime(date);
192             String JavaDoc st = new String JavaDoc(months[gc.get(gc.MONTH)]);
193
194             return st;
195         } catch (Throwable JavaDoc t) {
196             return "bad date!";
197         }
198     }
199
200     public void setMinimumRole(Role argRole) {
201         this.minimumRole = argRole;
202     }
203
204     /**
205      * Gets the value of minimumRole
206      *
207      * @return the value of minimumRole
208      * @hibernate.many-to-one
209      * column="MIN_WRITE_ROLE"
210      */

211     public Role getMinimumRole() {
212         return this.minimumRole;
213     }
214
215     /**
216      * Sets the value of name
217      *
218      * @param argName Value to assign to this.name
219      */

220     public void setName(String JavaDoc name) {
221         this.name = name;
222     }
223
224     /**
225      * Gets the value of name
226      *
227      * @return the value of name
228      * @hibernate.property
229      * column="NAME"
230      */

231     public String JavaDoc getName() {
232         return this.name;
233     }
234
235     /**
236      * Sets the value of person
237      *
238      * @param argPerson Value to assign to this.person
239      */

240     public void setPerson(String JavaDoc person) {
241         this.person = person;
242     }
243
244     /**
245      * Gets the value of person
246      *
247      * @return the value of person
248      * @hibernate.property
249      * column="PERSON"
250      */

251     public String JavaDoc getPerson() {
252         return this.person;
253     }
254
255     /**
256      * Sets the value of projectId
257      *
258      * @param argId Value to assign to this.id
259      */

260     public void setProjectId(Long JavaDoc argId) {
261         this.projectId = argId;
262     }
263
264     /**
265      * Gets the value of id
266      *
267      * @return the value of projectId
268      * @hibernate.property
269      * column="PROJECT_ID"
270      */

271     public Long JavaDoc getProjectId() {
272         return this.projectId;
273     }
274
275     /**
276      * Sets the value of question
277      *
278      * @param argQuestion Value to assign to this.question
279      */

280     public void setQuestion(String JavaDoc question) {
281         this.question = question;
282     }
283
284     /**
285      * Gets the value of question
286      *
287      * @return the value of question
288      * @hibernate.property
289      * column="QUESTION"
290      * length="3999"
291      */

292     public String JavaDoc getQuestion() {
293         return this.question;
294     }
295
296     /**
297      * Sets the value of sequence
298      *
299      * @param argId Value to assign to this.sequence
300      */

301     public void setSequence(Long JavaDoc argSequence) {
302         this.sequence = argSequence;
303     }
304
305     public void setSequence(String JavaDoc argSequence) {
306         try {
307             this.sequence = new Long JavaDoc(argSequence);
308         } catch (Throwable JavaDoc t) {
309             System.out.println("illegal sequence number");
310         }
311     }
312
313     /**
314      * Gets the value of sequence
315      *
316      * @return the value of sequence
317      * @hibernate.property
318      * column="SEQUENCE"
319      */

320     public Long JavaDoc getSequence() {
321         return this.sequence;
322     }
323
324     /**
325      * Sets the value of startDate
326      *
327      * @param argId Value to assign to this.startDate
328      */

329     public void setStartDate(Date JavaDoc argStartDate) {
330         this.startDate = argStartDate;
331     }
332
333     public void setStartDate(String JavaDoc year, String JavaDoc month, String JavaDoc day) {
334         startDate = setDate(year, month, day);
335     }
336
337     /**
338      * Gets the value of startDate
339      *
340      * @return the value of startDate
341      * @hibernate.property
342      * column="START_DATE"
343      */

344     public Date JavaDoc getStartDate() {
345         return this.startDate;
346     }
347
348     public static String JavaDoc getYear(Date JavaDoc date) {
349         try {
350             GregorianCalendar JavaDoc gc = new GregorianCalendar JavaDoc();
351             gc.setTime(date);
352             String JavaDoc st = new String JavaDoc("" + gc.get(gc.YEAR));
353
354             return st;
355         } catch (Throwable JavaDoc t) {
356             return "bad date!";
357         }
358     }
359
360     public String JavaDoc getEndDateDay() {
361         return getDay(endDate);
362     }
363
364     public String JavaDoc getEndDateMonth() {
365         return getMonth(endDate);
366     }
367
368     public String JavaDoc getStartDateAsString() {
369         return getDate(startDate);
370     }
371
372     public String JavaDoc getStartDateDay() {
373         return getDay(startDate);
374     }
375
376     public String JavaDoc getStartDateMonth() {
377         return getMonth(startDate);
378     }
379
380     public String JavaDoc getStartDateYear() {
381         return getYear(startDate);
382     }
383
384     /**
385      * Sets the value of status
386      *
387      * @param argQuestion Value to assign to this.status
388      */

389     public void setStatus(Boolean JavaDoc status) {
390         this.status = status;
391     }
392
393     /**
394      * Gets the value of status
395      *
396      * @return the value of status
397      * @hibernate.property
398      * column="STATUS"
399      */

400     public Boolean JavaDoc getStatus() {
401         return this.status;
402     }
403
404     /**
405      * Sets the value of voters
406      *
407      * @param voters Value to assign to this.voters
408      */

409     public void setVoters(List JavaDoc voters) {
410         this.voters = voters;
411     }
412
413     /**
414      * Gets the value of voters
415      *
416      * @return the value of voters
417      * @hibernate.list
418      * cascade="all"
419      * table="COEFFICIENT_VOTE_VOTERS"
420      * @hibernate.collection-key
421      * column="VOTE_ID"
422      * @hibernate.collection-index
423      * column="IDX"
424      * @hibernate.collection-element
425      * column="VOTERS"
426      * type="string"
427      */

428     public List JavaDoc getVoters() {
429         return this.voters;
430     }
431
432     public String JavaDoc dump() {
433         String JavaDoc st =
434             new String JavaDoc("\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 JavaDoc setDate(String JavaDoc year, String JavaDoc month, String JavaDoc day) {
445         int i;
446         int intYear;
447         int intMonth;
448         int intDay;
449
450         try {
451             intYear = Integer.parseInt(year);
452         } catch (Throwable JavaDoc t) {
453             intYear = 1900;
454         }
455
456         try {
457             intDay = Integer.parseInt(day);
458         } catch (Throwable JavaDoc 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 JavaDoc gc = new GregorianCalendar JavaDoc(intYear, intMonth, intDay);
472
473         return gc.getTime();
474     }
475
476     private String JavaDoc getDate(Date JavaDoc date) {
477         try {
478             GregorianCalendar JavaDoc gc = new GregorianCalendar JavaDoc();
479             gc.setTime(date);
480             String JavaDoc st =
481                 new String JavaDoc(gc.get(gc.DAY_OF_MONTH) + " "
482                     + months[gc.get(gc.MONTH)] + " " + gc.get(gc.YEAR));
483
484             return st;
485         } catch (Throwable JavaDoc t) {
486             return "bad date!";
487         }
488     }
489 }
490
Popular Tags