View Javadoc

1   /*
2   Copyright 2010 James Pether Sörling Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy of the License at http://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 
3   	$Id
4   */
5   package com.hack23.cia.model.sweden.impl;
6   
7   import javax.persistence.DiscriminatorColumn;
8   import javax.persistence.DiscriminatorType;
9   import javax.persistence.Entity;
10  import javax.persistence.GeneratedValue;
11  import javax.persistence.GenerationType;
12  import javax.persistence.Id;
13  import javax.persistence.Inheritance;
14  import javax.persistence.InheritanceType;
15  import javax.persistence.Transient;
16  import javax.persistence.Version;
17  
18  import org.hibernate.annotations.Cache;
19  import org.hibernate.annotations.CacheConcurrencyStrategy;
20  
21  import com.hack23.cia.model.core.impl.BaseEntity;
22  
23  /***
24   * The Class AbstractBallotMetaData.
25   */
26  @Entity
27  @Inheritance(strategy = InheritanceType.SINGLE_TABLE)
28  @DiscriminatorColumn(name = "ballotMetaDataType", discriminatorType = DiscriminatorType.STRING)
29  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
30  public abstract class AbstractBallotMetaData extends BaseEntity {
31  
32      /*** The Constant serialVersionUID. */
33      private static final long serialVersionUID = 6065382653371757540L;
34  
35  	/*** The absent votes. */
36      protected long absentVotes = 0;
37  
38      /*** The id. */
39      private Long id;
40  
41      /*** The neutral votes. */
42      protected long neutralVotes = 0;
43      
44      /*** The no votes. */
45      protected long noVotes = 0;
46  
47      /*** The total votes. */
48      protected long totalVotes = 0;
49  
50      /*** The version. */
51      private Long version=1L;
52  
53      /*** The yes votes. */
54      protected long yesVotes = 0;
55  
56      /***
57       * Instantiates a new abstract ballot meta data.
58       */
59      public AbstractBallotMetaData() {
60  		super();
61  	}
62  
63      /***
64       * Gets the absent votes.
65       *
66       * @return the absent votes
67       */
68      public long getAbsentVotes() {
69          return absentVotes;
70      }
71  
72      /*
73       * (non-Javadoc)
74       * 
75       * @see com.hack23.cia.model.core.BaseEntity#getId()
76       */
77      @Override
78      @Id
79      @GeneratedValue(strategy = GenerationType.AUTO)
80      public Long getId() {
81          return id;
82      }
83  
84      /***
85       * Gets the neutral votes.
86       *
87       * @return the neutral votes
88       */
89      public long getNeutralVotes() {
90          return neutralVotes;
91      }
92  
93      /***
94       * Gets the no votes.
95       *
96       * @return the no votes
97       */
98      public long getNoVotes() {
99          return noVotes;
100     }
101 
102     /***
103      * Gets the total votes.
104      *
105      * @return the total votes
106      */
107     public long getTotalVotes() {
108         return totalVotes;
109     }
110 
111     /* (non-Javadoc)
112      * @see com.hack23.cia.model.core.BaseEntity#getVersion()
113      */
114     @Override
115     @Version
116     public Long getVersion() {
117         return version;
118     }
119 
120     /***
121      * Gets the yes votes.
122      *
123      * @return the yes votes
124      */
125     public long getYesVotes() {
126         return yesVotes;
127     }
128 
129     /***
130      * New vote.
131      *
132      * @param vote the vote
133      */
134     @Transient
135     public void newVote(final Vote vote) {
136         totalVotes++;
137         if (vote.getPosition() != null) {
138             if (vote.getPosition().equals(Vote.Position.Absent)) {
139                 absentVotes++;
140             } else if (vote.getPosition().equals(Vote.Position.Neutral)) {
141                 neutralVotes++;
142             } else if (vote.getPosition().equals(Vote.Position.Yes)) {
143                 yesVotes++;
144             } else if (vote.getPosition().equals(Vote.Position.No)) {
145                 noVotes++;
146             }
147         }
148     }
149 
150     /***
151      * Sets the absent votes.
152      *
153      * @param absentVotes the new absent votes
154      */
155     public void setAbsentVotes(final long absentVotes) {
156         this.absentVotes = absentVotes;
157     }
158 
159     /***
160      * Sets the id.
161      *
162      * @param id the new id
163      */
164     public void setId(final Long id) {
165         this.id = id;
166     }
167 
168 	/***
169 	 * Sets the neutral votes.
170 	 *
171 	 * @param neutralVotes the new neutral votes
172 	 */
173     public void setNeutralVotes(final long neutralVotes) {
174         this.neutralVotes = neutralVotes;
175     }
176 
177 
178     /***
179      * Sets the no votes.
180      *
181      * @param noVotes the new no votes
182      */
183     public void setNoVotes(final long noVotes) {
184         this.noVotes = noVotes;
185     }
186 
187 
188     /***
189      * Sets the total votes.
190      *
191      * @param totalVotes the new total votes
192      */
193     public void setTotalVotes(final long totalVotes) {
194         this.totalVotes = totalVotes;
195     }
196 
197 
198     /***
199      * Sets the version.
200      *
201      * @param version the new version
202      */
203     public void setVersion(final Long version) {
204         this.version = version;
205     }
206 
207     /***
208      * Sets the yes votes.
209      *
210      * @param yesVotes the new yes votes
211      */
212     public void setYesVotes(final long yesVotes) {
213         this.yesVotes = yesVotes;
214     }
215     
216 }