diff options
| author | Samuel Tardieu <sam@rfc1149.net> | 2013-05-19 18:45:40 +0200 |
|---|---|---|
| committer | Samuel Tardieu <sam@rfc1149.net> | 2013-05-19 18:45:40 +0200 |
| commit | 1eba3b589fb265c3832d76d4ce51952e8a67c62e (patch) | |
| tree | 0c80315a4e9e6d6cc65d6582854f9913c38f9faf /main/src/cgeo/geocaching/sorting/DistanceComparator.java | |
| parent | f6b2099d8f8b4edc3eccab4ac396d983b05f9862 (diff) | |
| parent | a09d414466028179ac4c7737dd0336a6d38bc00d (diff) | |
| download | cgeo-1eba3b589fb265c3832d76d4ce51952e8a67c62e.zip cgeo-1eba3b589fb265c3832d76d4ce51952e8a67c62e.tar.gz cgeo-1eba3b589fb265c3832d76d4ce51952e8a67c62e.tar.bz2 | |
Merge branch 'fix-2733' into upstream
Conflicts:
main/res/values/strings_not_translatable.xml
Diffstat (limited to 'main/src/cgeo/geocaching/sorting/DistanceComparator.java')
| -rw-r--r-- | main/src/cgeo/geocaching/sorting/DistanceComparator.java | 19 |
1 files changed, 6 insertions, 13 deletions
diff --git a/main/src/cgeo/geocaching/sorting/DistanceComparator.java b/main/src/cgeo/geocaching/sorting/DistanceComparator.java index 7b0afbb..731e356 100644 --- a/main/src/cgeo/geocaching/sorting/DistanceComparator.java +++ b/main/src/cgeo/geocaching/sorting/DistanceComparator.java @@ -27,13 +27,10 @@ public class DistanceComparator extends AbstractCacheComparator { if (cachedDistances) { return; } - for (Geocache cache : list) { + for (final Geocache cache : list) { if (cache.getCoords() != null) { cache.setDistance(coords.distanceTo(cache.getCoords())); } - else { - cache.setDistance(null); - } } cachedDistances = true; } @@ -46,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; - } - if (cache1.getCoords() == null) { - return 1; - } - if (cache2.getCoords() == null) { - return -1; + final Float distance1 = cache1.getDistance(); + final Float distance2 = cache2.getDistance(); + if (distance1 == null) { + return distance2 == null ? 0 : 1; } - return Float.compare(cache1.getDistance(), cache2.getDistance()); + return distance2 == null ? -1 : Float.compare(distance1, distance2); } } |
