aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/sorting/StateComparator.java
blob: 787af5a3b10c9a9687e147eea63af2c943c7aff6 (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
32
package cgeo.geocaching.sorting;

import cgeo.geocaching.cgCache;

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

	@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.disabled) {
			return 1;
		}
		if (cache.archived) {
			return 2;
		}
		return 0;
	}

}