summaryrefslogtreecommitdiff
path: root/src/lq/QuoteUtil.java
diff options
context:
space:
mode:
authorKjetil Ørbekk <orbekk@pvv.ntnu.no>2010-09-04 02:03:44 -0400
committerKjetil Ørbekk <orbekk@pvv.ntnu.no>2010-09-04 02:03:44 -0400
commitec11abe2f142c45240fe9ff172aa13a2e089019f (patch)
treed4abb611a57beb433bb83beaf68a295c0238b82d /src/lq/QuoteUtil.java
parentb504b5fe05410bc259cd4349d1b51dc355eb0d90 (diff)
Add scorePoints to Quotes.
ScorePoints is used to order by score on the quote site. See Quote for the formula.
Diffstat (limited to 'src/lq/QuoteUtil.java')
-rw-r--r--src/lq/QuoteUtil.java9
1 files changed, 8 insertions, 1 deletions
diff --git a/src/lq/QuoteUtil.java b/src/lq/QuoteUtil.java
index 72b94af..37f857b 100644
--- a/src/lq/QuoteUtil.java
+++ b/src/lq/QuoteUtil.java
@@ -72,7 +72,7 @@ public class QuoteUtil {
Collections.sort(quotes,
new Comparator<Quote>() {
public int compare(Quote q1, Quote q2) {
- throw new RuntimeException("Score ordering not yet implemented");
+ return Doubles.signum(q2.getScorePoints() - q1.getScorePoints());
}
});
return quotes;
@@ -124,4 +124,11 @@ public class QuoteUtil {
pm.close();
}
}
+
+ public static void addVote(Quote quote, Vote vote) {
+ quote.setSumVotes(quote.getSumVotes() + vote.getRating());
+ quote.setNumVotes(quote.getNumVotes() + 1);
+ double scorePoints = (vote.getRating()-2.5) * Math.abs((vote.getRating()-2.5));
+ quote.setScorePoints(quote.getScorePoints() + scorePoints);
+ }
}