aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/sorting/VisitComparator.java
blob: 5dfeed4bb82499a5381acb3124671ab11690625a (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
package cgeo.geocaching.sorting;

import cgeo.geocaching.cgCache;

/**
 * sorts caches by last visited date
 * 
 */
public class VisitComparator extends AbstractCacheComparator {

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

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