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.DiscriminatorValue;
8   import javax.persistence.Entity;
9   import javax.persistence.EnumType;
10  import javax.persistence.Enumerated;
11  import javax.persistence.Transient;
12  
13  import org.hibernate.annotations.Cache;
14  import org.hibernate.annotations.CacheConcurrencyStrategy;
15  
16  import com.hack23.cia.model.sweden.impl.Vote.Position;
17  
18  /***
19   * The Class AbstractBallotResult.
20   */
21  @Entity
22  @DiscriminatorValue("AbstractBallotResult")
23  @Cache(usage = CacheConcurrencyStrategy.NONSTRICT_READ_WRITE)
24  public abstract class AbstractBallotResult extends AbstractBallotMetaData {
25  
26      /*** The Constant serialVersionUID. */
27      private static final long serialVersionUID = 6065382653371757540L;
28  
29  	/*** The opponent votes. */
30      protected long opponentVotes;
31      
32      /*** The winning position. */
33      protected Position winningPosition;
34      
35      /*** The winning votes. */
36      protected long winningVotes;
37  
38      /***
39       * Instantiates a new abstract ballot result.
40       */
41      public AbstractBallotResult() {
42  		super();
43  	}
44  
45      /***
46       * Calc winning position.
47       */
48      @Transient
49      public void calcWinningPosition() {
50          if (yesVotes > noVotes) {
51              setWinningPosition(Position.Yes);
52              opponentVotes = this.noVotes;
53              winningVotes = this.yesVotes;
54          } else if (noVotes > yesVotes) {
55              setWinningPosition(Position.No);
56              opponentVotes = this.yesVotes;
57              winningVotes = this.noVotes;
58          } else {
59              setWinningPosition(Position.Neutral);
60              opponentVotes = this.yesVotes + this.noVotes;
61              winningVotes = this.neutralVotes;
62          }
63      }
64  
65      /***
66       * Gets the opponent votes.
67       *
68       * @return the opponent votes
69       */
70  	public long getOpponentVotes() {
71  		return opponentVotes;
72  	}
73      
74      /***
75       * Gets the winning position.
76       *
77       * @return the winning position
78       */
79      @Enumerated(EnumType.STRING)
80      public Position getWinningPosition() {
81          return winningPosition;
82      }
83  
84  	/***
85  	 * Gets the winning votes.
86  	 *
87  	 * @return the winning votes
88  	 */
89  	public long getWinningVotes() {
90  		return winningVotes;
91  	}
92  
93  	/***
94  	 * Sets the opponent votes.
95  	 *
96  	 * @param opponentVotes the new opponent votes
97  	 */
98  	public void setOpponentVotes(final long opponentVotes) {
99  		this.opponentVotes = opponentVotes;
100 	}
101 
102 	/***
103 	 * Sets the winning position.
104 	 *
105 	 * @param winningPosition the new winning position
106 	 */
107     public void setWinningPosition(final Position winningPosition) {
108         this.winningPosition = winningPosition;
109     }
110 
111 	/***
112 	 * Sets the winning votes.
113 	 *
114 	 * @param winningVotes the new winning votes
115 	 */
116 	public void setWinningVotes(final long winningVotes) {
117 		this.winningVotes = winningVotes;
118 	}
119 
120 }