1
2
3
4
5
6 package com.hack23.cia.model.sweden.impl;
7
8 import java.util.Date;
9
10 import javax.persistence.DiscriminatorValue;
11 import javax.persistence.Entity;
12 import javax.persistence.Temporal;
13 import javax.persistence.TemporalType;
14 import javax.persistence.Transient;
15
16 import org.hibernate.annotations.Cache;
17 import org.hibernate.annotations.CacheConcurrencyStrategy;
18 import org.hibernate.annotations.Formula;
19
20 /***
21 * The Class ParliamentMemberBallotRecord.
22 */
23 @Entity
24 @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
25 @DiscriminatorValue("ParliamentMemberBallotRecord")
26 public class ParliamentMemberBallotRecord extends AbstractBallotMetaData {
27
28 /*** The Constant serialVersionUID. */
29 private static final long serialVersionUID = -7843524383033778447L;
30
31 /*** The first vote date. */
32 private Date firstVoteDate = new Date();
33
34 /*** The last vote date. */
35 private Date lastVoteDate = new Date(0L);
36
37 /*** The opponent. */
38 private long opponent = 0;
39
40 /*** The percentage absent. */
41 private long percentageAbsent;
42
43 /*** The percentage loosing. */
44 private long percentageLoosing;
45
46 /*** The percentage loyal. */
47 private long percentageLoyal;
48
49 /*** The percentage present. */
50 private long percentagePresent;
51
52 /*** The percentage rebel. */
53 private long percentageRebel;
54
55 /*** The percentage winning. */
56 private long percentageWinning;
57
58 /*** The rebel. */
59 private long rebel = 0;
60
61
62 /***
63 * Instantiates a new parliament member ballot record.
64 */
65 public ParliamentMemberBallotRecord() {
66 super();
67 }
68
69 /***
70 * Gets the first vote date.
71 *
72 * @return the first vote date
73 */
74 @Temporal(TemporalType.DATE)
75 public Date getFirstVoteDate() {
76 return firstVoteDate;
77 }
78
79 /***
80 * Gets the last vote date.
81 *
82 * @return the last vote date
83 */
84 @Temporal(TemporalType.DATE)
85 public Date getLastVoteDate() {
86 return lastVoteDate;
87 }
88
89 /***
90 * Gets the loyal.
91 *
92 * @return the loyal
93 */
94 @Transient
95 public long getLoyal() {
96 return (totalVotes - neutralVotes - rebel);
97 }
98
99 /***
100 * Gets the opponent.
101 *
102 * @return the opponent
103 */
104 public long getOpponent() {
105 return opponent;
106 }
107
108 /***
109 * Gets the percentage absent.
110 *
111 * @return the percentage absent
112 */
113 @Formula("(absentVotes * 100) / totalVotes")
114 public long getPercentageAbsent() {
115 return percentageAbsent;
116 }
117
118 /***
119 * Gets the percentage loosing.
120 *
121 * @return the percentage loosing
122 */
123 @Formula("(opponent * 100) / totalVotes")
124 public long getPercentageLoosing() {
125 return percentageLoosing;
126 }
127
128 /***
129 * Gets the percentage loyal.
130 *
131 * @return the percentage loyal
132 */
133 @Formula("(totalVotes - neutralVotes - rebel)*100/totalVotes")
134 public long getPercentageLoyal() {
135 return percentageLoyal;
136 }
137
138 /***
139 * Gets the percentage present.
140 *
141 * @return the percentage present
142 */
143 @Formula("(totalVotes - absentVotes) * 100/ totalVotes")
144 public long getPercentagePresent() {
145 return percentagePresent;
146 }
147
148 /***
149 * Gets the percentage rebel.
150 *
151 * @return the percentage rebel
152 */
153
154 @Formula("(rebel * 100)/ totalVotes")
155 public long getPercentageRebel() {
156 return percentageRebel;
157 }
158
159 /***
160 * Gets the percentage winning.
161 *
162 * @return the percentage winning
163 */
164 @Formula("(totalVotes -neutralVotes -absentVotes -opponent)* 100/ totalVotes")
165 public long getPercentageWinning() {
166 return percentageWinning;
167 }
168
169 /***
170 * Gets the present.
171 *
172 * @return the present
173 */
174 @Transient
175 public long getPresent() {
176 return (totalVotes - absentVotes);
177 }
178
179 /***
180 * Gets the rebel.
181 *
182 * @return the rebel
183 */
184 public long getRebel() {
185 return rebel;
186 }
187
188 /***
189 * Gets the winning.
190 *
191 * @return the winning
192 */
193 @Transient
194 public long getWinning() {
195 return (totalVotes - neutralVotes - absentVotes - opponent);
196 }
197
198
199
200
201 @Override
202 @Transient
203 public void newVote(final Vote vote) {
204 super.newVote(vote);
205
206 if (vote.getDatum().before(getFirstVoteDate())) {
207 setFirstVoteDate(vote.getDatum());
208 }
209
210 if (vote.getDatum().after(getLastVoteDate())) {
211 setLastVoteDate(vote.getDatum());
212 }
213 }
214
215 /***
216 * Sets the first vote date.
217 *
218 * @param firstVoteDate the new first vote date
219 */
220 public void setFirstVoteDate(final Date firstVoteDate) {
221 this.firstVoteDate = firstVoteDate;
222 }
223
224 /***
225 * Sets the last vote date.
226 *
227 * @param lastVoteDate the new last vote date
228 */
229 public void setLastVoteDate(final Date lastVoteDate) {
230 this.lastVoteDate = lastVoteDate;
231 }
232
233 /***
234 * Sets the opponent.
235 *
236 * @param opponent the new opponent
237 */
238 public void setOpponent(final long opponent) {
239 this.opponent = opponent;
240 }
241
242 /***
243 * Sets the percentage absent.
244 *
245 * @param percentageAbsent the new percentage absent
246 */
247 public void setPercentageAbsent(final long percentageAbsent) {
248 this.percentageAbsent = percentageAbsent;
249 }
250
251 /***
252 * Sets the percentage loosing.
253 *
254 * @param percentageLoosing the new percentage loosing
255 */
256 public void setPercentageLoosing(final long percentageLoosing) {
257 this.percentageLoosing = percentageLoosing;
258 }
259
260 /***
261 * Sets the percentage loyal.
262 *
263 * @param percentageLoyal the new percentage loyal
264 */
265 public void setPercentageLoyal(final long percentageLoyal) {
266 this.percentageLoyal = percentageLoyal;
267 }
268
269 /***
270 * Sets the percentage present.
271 *
272 * @param percentagePresent the new percentage present
273 */
274 public void setPercentagePresent(final long percentagePresent) {
275 this.percentagePresent = percentagePresent;
276 }
277
278 /***
279 * Sets the percentage rebel.
280 *
281 * @param percentageRebel the new percentage rebel
282 */
283 public void setPercentageRebel(final long percentageRebel) {
284 this.percentageRebel = percentageRebel;
285 }
286
287 /***
288 * Sets the percentage winning.
289 *
290 * @param percentageWinning the new percentage winning
291 */
292 public void setPercentageWinning(final long percentageWinning) {
293 this.percentageWinning = percentageWinning;
294 }
295
296
297 /***
298 * Sets the rebel.
299 *
300 * @param rebel the new rebel
301 */
302 public void setRebel(final long rebel) {
303 this.rebel = rebel;
304 }
305
306 }