PollOption.java
Upload User: gdxydsw
Upload Date: 2019-01-29
Package Size: 16721k
Code Size: 4k
Category:

Java Develop

Development Platform:

Java

  1. /*
  2.  * Copyright (c) JForum Team
  3.  * All rights reserved.
  4.  * 
  5.  * Redistribution and use in source and binary forms, 
  6.  * with or without modification, are permitted provided 
  7.  * that the following conditions are met:
  8.  * 
  9.  * 1) Redistributions of source code must retain the above 
  10.  * copyright notice, this list of conditions and the 
  11.  * following  disclaimer.
  12.  * 2)  Redistributions in binary form must reproduce the 
  13.  * above copyright notice, this list of conditions and 
  14.  * the following disclaimer in the documentation and/or 
  15.  * other materials provided with the distribution.
  16.  * 3) Neither the name of "Rafael Steil" nor 
  17.  * the names of its contributors may be used to endorse 
  18.  * or promote products derived from this software without 
  19.  * specific prior written permission.
  20.  * 
  21.  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT 
  22.  * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY 
  23.  * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, 
  24.  * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF 
  25.  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR 
  26.  * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL 
  27.  * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE 
  28.  * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, 
  29.  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES 
  30.  * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 
  31.  * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, 
  32.  * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER 
  33.  * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER 
  34.  * IN CONTRACT, STRICT LIABILITY, OR TORT 
  35.  * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN 
  36.  * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF 
  37.  * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
  38.  *
  39.  * This file creation date: 21/05/2004 - 15:17:46
  40.  * The JForum Project
  41.  * http://www.jforum.net
  42.  */
  43. package net.jforum.entities;
  44. import java.io.Serializable;
  45. /**
  46.  * @author David Almilli
  47.  * @version $Id: PollOption.java,v 1.4 2006/08/20 22:47:36 rafaelsteil Exp $
  48.  */
  49. public class PollOption implements Serializable {
  50. private int id;
  51. private int pollId;
  52. private String text;
  53. private int voteCount;
  54. private Poll poll;
  55. public PollOption() {}
  56. public PollOption(int id, String text, int voteCount) {
  57. this.id = id;
  58. this.text = text;
  59. this.voteCount = voteCount;
  60. }
  61. public int getId() {
  62. return id;
  63. }
  64. public void setId(int id) {
  65. this.id = id;
  66. }
  67. public int getPollId() {
  68. return pollId;
  69. }
  70. public void setPollId(int pollId) {
  71. this.pollId = pollId;
  72. }
  73. public String getText() {
  74. return text;
  75. }
  76. public void setText(String text) {
  77. this.text = text;
  78. }
  79. public int getVoteCount() {
  80. return voteCount;
  81. }
  82. public void setVoteCount(int voteCount) {
  83. this.voteCount = voteCount;
  84. }
  85. public int getVotePercentage() {
  86. int percent = 0;
  87. if (poll != null) {
  88. int totalCount = poll.getTotalVotes();
  89. percent = Math.round(100f*voteCount/totalCount);
  90. }
  91. return percent;
  92. }
  93. public Poll getPoll() {
  94. return poll;
  95. }
  96. protected void setPoll(Poll poll) {
  97. this.poll = poll;
  98. }
  99. /**
  100.  * @see java.lang.Object#toString()
  101.  */
  102. public String toString()
  103. {
  104. return new StringBuffer(128)
  105. .append('[')
  106. .append(this.id)
  107. .append(", ")
  108. .append(this.text)
  109. .append(", ")
  110. .append(this.voteCount)
  111. .append(']')
  112. .toString();
  113. }
  114. /**
  115.  * @see java.lang.Object#equals(java.lang.Object)
  116.  */
  117. public boolean equals(Object o)
  118. {
  119. if (!(o instanceof PollOption)) {
  120. return false;
  121. }
  122. PollOption po = (PollOption)o;
  123. return po.getId() == this.id
  124. && po.getText().equals(this.text)
  125. && po.getVoteCount() == this.voteCount;
  126. }
  127. /**
  128.  * @see java.lang.Object#hashCode()
  129.  */
  130. public int hashCode()
  131. {
  132. int result = 17;
  133. result *= 37 + this.id;
  134. result *= 37 + this.text.hashCode();
  135. result *= 37 + this.voteCount;
  136. return result;
  137. }
  138. }