diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2013-12-17 07:32:57 +0100 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2013-12-17 07:32:57 +0100 |
| commit | 235cfd8f5afa62bf4a2c924cec9cd7013874b10e (patch) | |
| tree | 8bae95f988c2a2f053d4acd8b363b6dde3dd165f | |
| parent | 537762a5a2e1d1dcfe7f990ef31c5c9a86d8c457 (diff) | |
| download | cgeo-235cfd8f5afa62bf4a2c924cec9cd7013874b10e.zip cgeo-235cfd8f5afa62bf4a2c924cec9cd7013874b10e.tar.gz cgeo-235cfd8f5afa62bf4a2c924cec9cd7013874b10e.tar.bz2 | |
refactoring: remove code duplication
3 files changed, 20 insertions, 26 deletions
diff --git a/main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java b/main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java index 2dee713..a23d135 100644 --- a/main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java +++ b/main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java @@ -1,6 +1,8 @@ package cgeo.geocaching.sorting; +import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; +import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.utils.Log; @@ -45,4 +47,22 @@ public abstract class AbstractCacheComparator implements CacheComparator { * cache2. */ protected abstract int compareCaches(final Geocache cache1, final Geocache cache2); + + /** + * Get number of overall finds for a cache. + * + * @param cache + * @return + */ + protected static int getFindsCount(Geocache cache) { + if (cache.getLogCounts().isEmpty()) { + cache.setLogCounts(DataStore.loadLogCounts(cache.getGeocode())); + } + Integer logged = cache.getLogCounts().get(LogType.FOUND_IT); + if (logged != null) { + return logged; + } + return 0; + } + } diff --git a/main/src/cgeo/geocaching/sorting/FindsComparator.java b/main/src/cgeo/geocaching/sorting/FindsComparator.java index b147fad..d2aebe3 100644 --- a/main/src/cgeo/geocaching/sorting/FindsComparator.java +++ b/main/src/cgeo/geocaching/sorting/FindsComparator.java @@ -1,8 +1,6 @@ package cgeo.geocaching.sorting; -import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; -import cgeo.geocaching.enumerations.LogType; public class FindsComparator extends AbstractCacheComparator { @@ -18,15 +16,4 @@ public class FindsComparator extends AbstractCacheComparator { return finds2 - finds1; } - private static int getFindsCount(Geocache cache) { - if (cache.getLogCounts().isEmpty()) { - cache.setLogCounts(DataStore.loadLogCounts(cache.getGeocode())); - } - Integer logged = cache.getLogCounts().get(LogType.FOUND_IT); - if (logged != null) { - return logged; - } - return 0; - } - } diff --git a/main/src/cgeo/geocaching/sorting/PopularityRatioComparator.java b/main/src/cgeo/geocaching/sorting/PopularityRatioComparator.java index b5edf17..2c42146 100644 --- a/main/src/cgeo/geocaching/sorting/PopularityRatioComparator.java +++ b/main/src/cgeo/geocaching/sorting/PopularityRatioComparator.java @@ -3,9 +3,7 @@ */ package cgeo.geocaching.sorting; -import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; -import cgeo.geocaching.enumerations.LogType; /** * sorts caches by popularity ratio (favorites per find in %). @@ -41,15 +39,4 @@ public class PopularityRatioComparator extends AbstractCacheComparator { return 0; } - - private static int getFindsCount(Geocache cache) { - if (cache.getLogCounts().isEmpty()) { - cache.setLogCounts(DataStore.loadLogCounts(cache.getGeocode())); - } - Integer logged = cache.getLogCounts().get(LogType.FOUND_IT); - if (logged != null) { - return logged; - } - return 0; - } } |
