1 43 package net.jforum.entities; 44 45 import java.io.Serializable ; 46 import java.util.ArrayList ; 47 import java.util.Calendar ; 48 import java.util.Date ; 49 import java.util.Iterator ; 50 import java.util.List ; 51 52 53 57 public class Poll implements Serializable { 58 private int id; 59 private int topicId; 60 private int length; 61 private String label; 62 private Date startTime; 63 private transient PollChanges pollChanges; 64 private List options = new ArrayList (); 65 66 public int getId() { 67 return id; 68 } 69 public void setId(int id) { 70 this.id = id; 71 } 72 public int getTopicId() { 73 return topicId; 74 } 75 public void setTopicId(int topicId) { 76 this.topicId = topicId; 77 } 78 public int getLength() { 79 return length; 80 } 81 public void setLength(int length) { 82 this.length = length; 83 } 84 public String getLabel() { 85 return label; 86 } 87 public void setLabel(String label) { 88 this.label = label; 89 } 90 public Date getStartTime() { 91 return startTime; 92 } 93 public void setStartTime(Date startTime) { 94 this.startTime = startTime; 95 } 96 public void addOption(PollOption option) { 97 options.add(option); 98 option.setPoll(this); 99 } 100 public void removeOption(PollOption option) { 101 if (options.remove(option)) { 102 option.setPoll(null); 103 } 104 } 105 public List getOptions() { 106 return options; 107 } 108 109 public void setChanges(PollChanges changes) { 110 this.pollChanges = changes; 111 } 112 113 public PollChanges getChanges() { 114 return this.pollChanges; 115 } 116 117 public int getTotalVotes() { 118 int votes = 0; 119 Iterator iter = options.iterator(); 120 while (iter.hasNext()) { 121 PollOption option = (PollOption)iter.next(); 122 votes += option.getVoteCount(); 123 } 124 return votes; 125 } 126 127 public boolean isOpen() { 128 if (length == 0) { 129 return true; 130 } 131 Calendar endTime = Calendar.getInstance(); 132 endTime.setTime(startTime); 133 endTime.add(Calendar.DAY_OF_YEAR, length); 134 return System.currentTimeMillis() < endTime.getTimeInMillis(); 135 } 136 } 137 | Popular Tags |