diff options
Diffstat (limited to 'main/src/cgeo/geocaching/sorting/DateComparator.java')
-rw-r--r-- | main/src/cgeo/geocaching/sorting/DateComparator.java | 22 |
1 files changed, 13 insertions, 9 deletions
diff --git a/main/src/cgeo/geocaching/sorting/DateComparator.java b/main/src/cgeo/geocaching/sorting/DateComparator.java index 7913941..347eb44 100644 --- a/main/src/cgeo/geocaching/sorting/DateComparator.java +++ b/main/src/cgeo/geocaching/sorting/DateComparator.java @@ -1,7 +1,7 @@ package cgeo.geocaching.sorting; -import cgeo.geocaching.CgeoApplication; import cgeo.geocaching.Geocache; +import cgeo.geocaching.sensors.Sensors; import java.util.ArrayList; import java.util.Date; @@ -9,21 +9,16 @@ import java.util.Date; /** * compares caches by date */ -public class DateComparator extends AbstractCacheComparator { +class DateComparator extends AbstractCacheComparator { @Override - protected int compareCaches(Geocache cache1, Geocache cache2) { + protected int compareCaches(final Geocache cache1, final Geocache cache2) { final Date date1 = cache1.getHiddenDate(); final Date date2 = cache2.getHiddenDate(); if (date1 != null && date2 != null) { final int dateDifference = date1.compareTo(date2); - // for equal dates, sort by distance if (dateDifference == 0) { - final ArrayList<Geocache> list = new ArrayList<>(); - list.add(cache1); - list.add(cache2); - final DistanceComparator distanceComparator = new DistanceComparator(CgeoApplication.getInstance().currentGeo().getCoords(), list); - return distanceComparator.compare(cache1, cache2); + return sortSameDate(cache1, cache2); } return dateDifference; } @@ -35,4 +30,13 @@ public class DateComparator extends AbstractCacheComparator { } return 0; } + + @SuppressWarnings("static-method") + protected int sortSameDate(final Geocache cache1, final Geocache cache2) { + final ArrayList<Geocache> list = new ArrayList<>(); + list.add(cache1); + list.add(cache2); + final DistanceComparator distanceComparator = new DistanceComparator(Sensors.getInstance().currentGeo().getCoords(), list); + return distanceComparator.compare(cache1, cache2); + } } |