diff options
Diffstat (limited to 'src/lq/QuoteUtil.java')
-rw-r--r-- | src/lq/QuoteUtil.java | 9 |
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); + } } |