diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2013-05-19 17:27:08 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2013-05-19 17:27:08 +0200 |
| commit | a09d414466028179ac4c7737dd0336a6d38bc00d (patch) | |
| tree | d94f4fdc74a00940b14f9f0e7246ca4e8bbe99c2 /main/src/cgeo/geocaching/sorting | |
| parent | 7125a7adbaf3cad9687a225032c85a9e7391c603 (diff) | |
| download | cgeo-a09d414466028179ac4c7737dd0336a6d38bc00d.zip cgeo-a09d414466028179ac4c7737dd0336a6d38bc00d.tar.gz cgeo-a09d414466028179ac4c7737dd0336a6d38bc00d.tar.bz2 | |
enhancement: make the distance comparator work with approximate distance
Part of work on #2733.
Diffstat (limited to 'main/src/cgeo/geocaching/sorting')
| -rw-r--r-- | main/src/cgeo/geocaching/sorting/DistanceComparator.java | 14 |
1 files changed, 5 insertions, 9 deletions
diff --git a/main/src/cgeo/geocaching/sorting/DistanceComparator.java b/main/src/cgeo/geocaching/sorting/DistanceComparator.java index c34ae96..731e356 100644 --- a/main/src/cgeo/geocaching/sorting/DistanceComparator.java +++ b/main/src/cgeo/geocaching/sorting/DistanceComparator.java @@ -43,16 +43,12 @@ public class DistanceComparator extends AbstractCacheComparator { @Override protected int compareCaches(final Geocache cache1, final Geocache cache2) { calculateAllDistances(); - if (cache1.getCoords() == null && cache2.getCoords() == null) { - return 0; + final Float distance1 = cache1.getDistance(); + final Float distance2 = cache2.getDistance(); + if (distance1 == null) { + return distance2 == null ? 0 : 1; } - if (cache1.getCoords() == null) { - return 1; - } - if (cache2.getCoords() == null) { - return -1; - } - return Float.compare(cache1.getDistance(), cache2.getDistance()); + return distance2 == null ? -1 : Float.compare(distance1, distance2); } } |
