1 54 55 package org.apache.jetspeed.portal.portlets.util.poll; 56 57 63 public class AnswerGroup { 64 65 private Answer[] answers = new Answer[0]; 66 67 73 public AnswerGroup( Answer[] answers ) { 74 this.answers = answers; 75 } 76 77 83 public Answer getTopAnswer() { 84 85 Answer top = null; 86 87 for ( int i = 0; i < answers.length; ++i ) { 88 89 90 if ( top == null || 91 this.answers[i].getVoteCount() > top.getVoteCount() ) { 92 93 top = this.answers[i]; 94 continue; 95 96 } 97 98 } 99 100 return top; 101 102 } 103 104 110 public Answer getAnswer( int id ) { 111 112 for ( int i = 0; i < answers.length; ++i ) { 113 114 if ( answers[i].getID() == id ) { 115 return answers[i]; 116 } 117 } 118 119 return null; 120 } 121 122 128 public Answer[] getAnswers() { 129 return this.answers; 130 } 131 132 138 public int getPercentage( Answer answer ) { 139 140 int total = this.getTotal(); 141 int votes = answer.getVoteCount(); 142 143 if ( total == 0 || 144 votes == 0 ) { 145 146 return 0; 147 } 148 149 float percentage = ((float) votes / total * 100); 150 151 return (int)percentage; 152 153 } 154 155 161 public int getTotal() { 162 163 int total = 0; 164 165 for ( int i = 0; i < answers.length; ++i ) { 166 total += answers[i].getVoteCount(); 167 } 168 169 return total; 170 } 171 172 } 173 | Popular Tags |