aboutsummaryrefslogtreecommitdiffstats
path: root/main/src/cgeo/geocaching/sorting/StateComparator.java
blob: bda514f31e4dd8cb802056aa863fc8ba8e3b7eb8 (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
26
27
28
29
30
31
package cgeo.geocaching.sorting;

import cgeo.geocaching.cgCache;

/**
 * sort caches by state (normal, disabled, archived)
 *
 */
public class StateComparator extends AbstractCacheComparator {

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

    @Override
    protected int compareCaches(final cgCache cache1, final cgCache cache2) {
        return getState(cache1) - getState(cache2);
    }

    private static int getState(final cgCache cache) {
        if (cache.isDisabled()) {
            return 1;
        }
        if (cache.isArchived()) {
            return 2;
        }
        return 0;
    }

}