aboutsummaryrefslogtreecommitdiffstats
path: root/src/cgeo/geocaching/sorting/FindsComparator.java
blob: 8553f4be85d8177b80933d3443f78100a963873e (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
33
34
35
36
37
38
39
40
package cgeo.geocaching.sorting;

import cgeo.geocaching.cgBase;
import cgeo.geocaching.cgCache;
import cgeo.geocaching.cgeoapplication;

public class FindsComparator extends AbstractCacheComparator implements
		CacheComparator {

	private cgeoapplication app;

	public FindsComparator(cgeoapplication app) {
		this.app = app;
	}

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

	@Override
	protected int compareCaches(cgCache cache1, cgCache cache2) {
		int finds1 = getFindsCount(cache1);
		int finds2 = getFindsCount(cache2);
		return finds2 - finds1;
	}

	private int getFindsCount(cgCache cache) {
		int finds = 0;
		if (cache.logCounts.isEmpty()) {
			cache.logCounts = app.loadLogCounts(cache.geocode);
		}
		Integer logged = cache.logCounts.get(cgBase.LOG_FOUND_IT);
		if (logged != null) {
			finds = logged;
		}
		return finds;
	}

}