diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2011-08-28 15:11:21 +0200 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2011-08-28 15:11:21 +0200 |
| commit | 0494869b02ae0cd6e8734c6667b4c64c4217b974 (patch) | |
| tree | 000ebfe083793800cb00bad70d5fff7bf4ae57f2 /src/cgeo/geocaching/sorting | |
| parent | c683867ae0db28093c91378180bc6a7e2c9ab8d0 (diff) | |
| download | cgeo-0494869b02ae0cd6e8734c6667b4c64c4217b974.zip cgeo-0494869b02ae0cd6e8734c6667b4c64c4217b974.tar.gz cgeo-0494869b02ae0cd6e8734c6667b4c64c4217b974.tar.bz2 | |
new: sort by finds count, fixes #231
Diffstat (limited to 'src/cgeo/geocaching/sorting')
| -rw-r--r-- | src/cgeo/geocaching/sorting/FindsComparator.java | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/src/cgeo/geocaching/sorting/FindsComparator.java b/src/cgeo/geocaching/sorting/FindsComparator.java new file mode 100644 index 0000000..8553f4b --- /dev/null +++ b/src/cgeo/geocaching/sorting/FindsComparator.java @@ -0,0 +1,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; + } + +} |
