001: /*
002: * Copyright (c) JForum Team
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms,
006: * with or without modification, are permitted provided
007: * that the following conditions are met:
008: *
009: * 1) Redistributions of source code must retain the above
010: * copyright notice, this list of conditions and the
011: * following disclaimer.
012: * 2) Redistributions in binary form must reproduce the
013: * above copyright notice, this list of conditions and
014: * the following disclaimer in the documentation and/or
015: * other materials provided with the distribution.
016: * 3) Neither the name of "Rafael Steil" nor
017: * the names of its contributors may be used to endorse
018: * or promote products derived from this software without
019: * specific prior written permission.
020: *
021: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT
022: * HOLDERS AND CONTRIBUTORS "AS IS" AND ANY
023: * EXPRESS OR IMPLIED WARRANTIES, INCLUDING,
024: * BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
025: * MERCHANTABILITY AND FITNESS FOR A PARTICULAR
026: * PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
027: * THE COPYRIGHT OWNER OR CONTRIBUTORS BE LIABLE
028: * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
029: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES
030: * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
031: * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA,
032: * OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER
033: * CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER
034: * IN CONTRACT, STRICT LIABILITY, OR TORT
035: * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
036: * ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
037: * ADVISED OF THE POSSIBILITY OF SUCH DAMAGE
038: *
039: * This file creation date: 21/05/2004 - 15:17:46
040: * The JForum Project
041: * http://www.jforum.net
042: */
043: package net.jforum.entities;
044:
045: import java.io.Serializable;
046:
047: /**
048: * @author David Almilli
049: * @version $Id: PollOption.java,v 1.4 2006/08/20 22:47:36 rafaelsteil Exp $
050: */
051: public class PollOption implements Serializable {
052: private int id;
053: private int pollId;
054: private String text;
055: private int voteCount;
056:
057: private Poll poll;
058:
059: public PollOption() {
060: }
061:
062: public PollOption(int id, String text, int voteCount) {
063: this .id = id;
064: this .text = text;
065: this .voteCount = voteCount;
066: }
067:
068: public int getId() {
069: return id;
070: }
071:
072: public void setId(int id) {
073: this .id = id;
074: }
075:
076: public int getPollId() {
077: return pollId;
078: }
079:
080: public void setPollId(int pollId) {
081: this .pollId = pollId;
082: }
083:
084: public String getText() {
085: return text;
086: }
087:
088: public void setText(String text) {
089: this .text = text;
090: }
091:
092: public int getVoteCount() {
093: return voteCount;
094: }
095:
096: public void setVoteCount(int voteCount) {
097: this .voteCount = voteCount;
098: }
099:
100: public int getVotePercentage() {
101: int percent = 0;
102: if (poll != null) {
103: int totalCount = poll.getTotalVotes();
104: percent = Math.round(100f * voteCount / totalCount);
105: }
106: return percent;
107: }
108:
109: public Poll getPoll() {
110: return poll;
111: }
112:
113: protected void setPoll(Poll poll) {
114: this .poll = poll;
115: }
116:
117: /**
118: * @see java.lang.Object#toString()
119: */
120: public String toString() {
121: return new StringBuffer(128).append('[').append(this .id)
122: .append(", ").append(this .text).append(", ").append(
123: this .voteCount).append(']').toString();
124: }
125:
126: /**
127: * @see java.lang.Object#equals(java.lang.Object)
128: */
129: public boolean equals(Object o) {
130: if (!(o instanceof PollOption)) {
131: return false;
132: }
133:
134: PollOption po = (PollOption) o;
135: return po.getId() == this .id && po.getText().equals(this .text)
136: && po.getVoteCount() == this .voteCount;
137: }
138:
139: /**
140: * @see java.lang.Object#hashCode()
141: */
142: public int hashCode() {
143: int result = 17;
144:
145: result *= 37 + this .id;
146: result *= 37 + this .text.hashCode();
147: result *= 37 + this.voteCount;
148:
149: return result;
150: }
151: }
|