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

import cgeo.geocaching.cgCache;

/**
 * sorts caches by popularity (favorite count)
 *
 */
public class PopularityComparator extends AbstractCacheComparator {

    @Override
    protected boolean canCompare(cgCache cache1, cgCache cache2) {
        return cache1.getFavouriteCnt() != null && cache2.getFavouriteCnt() != null;
    }

    @Override
    protected int compareCaches(cgCache cache1, cgCache cache2) {
        if (cache1.getFavouriteCnt() < cache2.getFavouriteCnt()) {
            return 1;
        } else if (cache2.getFavouriteCnt() < cache1.getFavouriteCnt()) {
            return -1;
        }
        return 0;
    }
}