diff options
| author | Bananeweizen <bananeweizen@gmx.de> | 2013-11-10 16:59:47 +0100 |
|---|---|---|
| committer | Bananeweizen <bananeweizen@gmx.de> | 2013-11-10 16:59:47 +0100 |
| commit | 872025eafaf433891f5daf96fe69ef8db1739a05 (patch) | |
| tree | 7943dfd498c37417ddf17df90880b03748194a9c /main/src/cgeo | |
| parent | e4627ac2425adbdddf6f7750eb2cbba7f5e3204b (diff) | |
| download | cgeo-872025eafaf433891f5daf96fe69ef8db1739a05.zip cgeo-872025eafaf433891f5daf96fe69ef8db1739a05.tar.gz cgeo-872025eafaf433891f5daf96fe69ef8db1739a05.tar.bz2 | |
refactoring: remove bad compare method of waypoints
Diffstat (limited to 'main/src/cgeo')
| -rw-r--r-- | main/src/cgeo/geocaching/CacheDetailActivity.java | 2 | ||||
| -rw-r--r-- | main/src/cgeo/geocaching/Waypoint.java | 21 |
2 files changed, 13 insertions, 10 deletions
diff --git a/main/src/cgeo/geocaching/CacheDetailActivity.java b/main/src/cgeo/geocaching/CacheDetailActivity.java index 89e78d6..d0273c5 100644 --- a/main/src/cgeo/geocaching/CacheDetailActivity.java +++ b/main/src/cgeo/geocaching/CacheDetailActivity.java @@ -1826,7 +1826,7 @@ public class CacheDetailActivity extends AbstractViewPagerActivity<CacheDetailAc // sort waypoints: PP, Sx, FI, OWN final List<Waypoint> sortedWaypoints = new ArrayList<Waypoint>(cache.getWaypoints()); - Collections.sort(sortedWaypoints); + Collections.sort(sortedWaypoints, Waypoint.WAYPOINT_COMPARATOR); view = (ListView) getLayoutInflater().inflate(R.layout.cachedetail_waypoints_page, null); view.setClickable(true); diff --git a/main/src/cgeo/geocaching/Waypoint.java b/main/src/cgeo/geocaching/Waypoint.java index 6f28aa1..e1a8b2f 100644 --- a/main/src/cgeo/geocaching/Waypoint.java +++ b/main/src/cgeo/geocaching/Waypoint.java @@ -5,14 +5,12 @@ import cgeo.geocaching.geopoint.Geopoint; import org.apache.commons.lang3.StringUtils; +import java.util.Comparator; import java.util.HashMap; import java.util.List; import java.util.Map; -/** - * Note: this class has a natural ordering that is inconsistent with equals. - */ -public class Waypoint implements IWaypoint, Comparable<Waypoint> { +public class Waypoint implements IWaypoint { public static final String PREFIX_OWN = "OWN"; private static final int ORDER_UNDEFINED = -2; @@ -135,11 +133,6 @@ public class Waypoint implements IWaypoint, Comparable<Waypoint> { return cachedOrder; } - @Override - public int compareTo(Waypoint other) { - return order() - other.order(); - } - public String getPrefix() { return prefix; } @@ -254,4 +247,14 @@ public class Waypoint implements IWaypoint, Comparable<Waypoint> { return (int) hash; } + /** + * Sort waypoints by their probable order (e.g. parking first, final last). + */ + public static final Comparator<? super Waypoint> WAYPOINT_COMPARATOR = new Comparator<Waypoint>() { + + @Override + public int compare(Waypoint left, Waypoint right) { + return left.order() - right.order(); + } + }; } |
