Example usage for java.util Comparators.ImageSortByFinalVoteCount Comparators.ImageSortByFinalVoteCount

List of usage examples for java.util Comparators.ImageSortByFinalVoteCount Comparators.ImageSortByFinalVoteCount

Introduction

In this page you can find the example usage for java.util Comparators.ImageSortByFinalVoteCount Comparators.ImageSortByFinalVoteCount.

Prototype

Comparators.ImageSortByFinalVoteCount

Source Link

Usage

From source file:net.chrissearle.flickrvote.service.DaoChallengeService.java

/**
 * Method doRanking calculates rank based on score
 *
 * @param images of type List<Image>
 *///from  ww w .  java2 s  . c o m
private void doRanking(List<Image> images) {
    long rank = 0;
    long lastSeenValue = Long.MAX_VALUE;

    Collections.sort(images, new Comparators.ImageSortByFinalVoteCount());

    for (Image image : images) {
        if (image.getFinalVoteCount() < lastSeenValue) {
            lastSeenValue = image.getFinalVoteCount();
            rank++;
        }

        if (logger.isLoggable(Level.INFO)) {
            logger.info("Setting final rank for " + image.getId() + " to " + rank);
        }
        image.setFinalRank(rank);
        imageDao.persist(image);
    }
}