From 82661d89ea3159000ae42fbbc0d45d663776dbee Mon Sep 17 00:00:00 2001 From: Bananeweizen Date: Thu, 19 Dec 2013 14:29:46 +0100 Subject: refactoring: remove duplicate code --- main/src/cgeo/geocaching/Geocache.java | 17 +++++++++++++++++ .../geocaching/sorting/AbstractCacheComparator.java | 19 ------------------- main/src/cgeo/geocaching/sorting/FindsComparator.java | 4 ++-- .../geocaching/sorting/PopularityRatioComparator.java | 4 ++-- 4 files changed, 21 insertions(+), 23 deletions(-) diff --git a/main/src/cgeo/geocaching/Geocache.java b/main/src/cgeo/geocaching/Geocache.java index bded7d0..241f180 100644 --- a/main/src/cgeo/geocaching/Geocache.java +++ b/main/src/cgeo/geocaching/Geocache.java @@ -1813,4 +1813,21 @@ public class Geocache implements ICache, IWaypoint { public String getWaypointPrefix(String name) { return getConnector().getWaypointPrefix(name); } + + /** + * Get number of overall finds for a cache, or 0 if the number of finds is not known. + * + * @return + */ + public int getFindsCount() { + if (getLogCounts().isEmpty()) { + setLogCounts(DataStore.loadLogCounts(getGeocode())); + } + Integer logged = getLogCounts().get(LogType.FOUND_IT); + if (logged != null) { + return logged; + } + return 0; + } + } diff --git a/main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java b/main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java index a23d135..a1c04a4 100644 --- a/main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java +++ b/main/src/cgeo/geocaching/sorting/AbstractCacheComparator.java @@ -1,8 +1,6 @@ package cgeo.geocaching.sorting; -import cgeo.geocaching.DataStore; import cgeo.geocaching.Geocache; -import cgeo.geocaching.enumerations.LogType; import cgeo.geocaching.utils.Log; @@ -48,21 +46,4 @@ public abstract class AbstractCacheComparator implements CacheComparator { */ 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 d2aebe3..c889776 100644 --- a/main/src/cgeo/geocaching/sorting/FindsComparator.java +++ b/main/src/cgeo/geocaching/sorting/FindsComparator.java @@ -11,8 +11,8 @@ public class FindsComparator extends AbstractCacheComparator { @Override protected int compareCaches(Geocache cache1, Geocache cache2) { - int finds1 = getFindsCount(cache1); - int finds2 = getFindsCount(cache2); + int finds1 = cache1.getFindsCount(); + int finds2 = cache2.getFindsCount(); return finds2 - finds1; } diff --git a/main/src/cgeo/geocaching/sorting/PopularityRatioComparator.java b/main/src/cgeo/geocaching/sorting/PopularityRatioComparator.java index 2c42146..f438762 100644 --- a/main/src/cgeo/geocaching/sorting/PopularityRatioComparator.java +++ b/main/src/cgeo/geocaching/sorting/PopularityRatioComparator.java @@ -21,8 +21,8 @@ public class PopularityRatioComparator extends AbstractCacheComparator { float ratio1 = 0.0f; float ratio2 = 0.0f; - int finds1 = getFindsCount(cache1); - int finds2 = getFindsCount(cache2); + int finds1 = cache1.getFindsCount(); + int finds2 = cache2.getFindsCount(); if (finds1 != 0) { ratio1 = (((float) cache1.getFavoritePoints()) / ((float) finds1)); -- cgit v1.1