aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/sorting/RatingComparator.java
blob: be071c5717e16a62a4c8ac0fe1e629ee59596ed9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package cgeo.geocaching.sorting;

import cgeo.geocaching.cgCache;

/**
 * sorts caches by gcvote.com rating
 *
 */
public class RatingComparator extends AbstractCacheComparator {

    @Override
    protected boolean canCompare(final cgCache cache1, final cgCache cache2) {
        return true;
    }

    @Override
    protected int compareCaches(final cgCache cache1, final cgCache cache2) {
        final float rating1 = cache1.getRating();
        final float rating2 = cache2.getRating();
        // Voting can be disabled for caches, then assume an average rating instead
        return Float.compare(rating2 != 0.0 ? rating2 : 2.5f, rating1 != 0.0 ? rating1 : 2.5f);
    }
}