aboutsummaryrefslogtreecommitdiffstats
path: root/main
diff options
context:
space:
mode:
authorSamuel Tardieu <sam@rfc1149.net>2012-04-11 09:59:41 +0200
committerSamuel Tardieu <sam@rfc1149.net>2012-04-11 15:45:32 +0200
commit138fb60259388ffe469e435a70f79e8676b96e05 (patch)
tree626530910734bd51e4bc0444131fbc1c26099128 /main
parent48cfc74434c22e2d54b32cc659877e648536e818 (diff)
downloadcgeo-138fb60259388ffe469e435a70f79e8676b96e05.zip
cgeo-138fb60259388ffe469e435a70f79e8676b96e05.tar.gz
cgeo-138fb60259388ffe469e435a70f79e8676b96e05.tar.bz2
Implement equals() and hashCode() for Geopoint
Diffstat (limited to 'main')
-rw-r--r--main/src/cgeo/geocaching/cgCache.java2
-rw-r--r--main/src/cgeo/geocaching/geopoint/Geopoint.java29
2 files changed, 18 insertions, 13 deletions
diff --git a/main/src/cgeo/geocaching/cgCache.java b/main/src/cgeo/geocaching/cgCache.java
index 5a14155..36fd064 100644
--- a/main/src/cgeo/geocaching/cgCache.java
+++ b/main/src/cgeo/geocaching/cgCache.java
@@ -308,7 +308,7 @@ public class cgCache implements ICache, IWaypoint {
premiumMembersOnly == other.premiumMembersOnly &&
difficulty == other.difficulty &&
terrain == other.terrain &&
- (coords != null ? coords.isEqualTo(other.coords) : null == other.coords) &&
+ (coords != null ? coords.equals(other.coords) : null == other.coords) &&
reliableLatLon == other.reliableLatLon &&
disabled == other.disabled &&
archived == other.archived &&
diff --git a/main/src/cgeo/geocaching/geopoint/Geopoint.java b/main/src/cgeo/geocaching/geopoint/Geopoint.java
index 31079bc..93d9c87 100644
--- a/main/src/cgeo/geocaching/geopoint/Geopoint.java
+++ b/main/src/cgeo/geocaching/geopoint/Geopoint.java
@@ -114,7 +114,7 @@ public final class Geopoint implements ICoordinates {
*/
public int getLatitudeE6()
{
- return (int) (latitude * 1E6);
+ return (int) Math.round(latitude * 1E6);
}
/**
@@ -134,7 +134,7 @@ public final class Geopoint implements ICoordinates {
*/
public int getLongitudeE6()
{
- return (int) (longitude * 1E6);
+ return (int) Math.round(longitude * 1E6);
}
/**
@@ -200,16 +200,21 @@ public final class Geopoint implements ICoordinates {
return new Geopoint(rlat * rad2deg, rlon * rad2deg);
}
- /**
- * Checks if given Geopoint is identical with this Geopoint.
- *
- * @param gp
- * Geopoint to check
- * @return true if identical, false otherwise
- */
- public boolean isEqualTo(Geopoint gp)
- {
- return null != gp && gp.latitude == latitude && gp.longitude == longitude;
+ @Override
+ public boolean equals(final Object obj) {
+ if (this == obj) {
+ return true;
+ }
+ if (obj == null || !(obj instanceof Geopoint)) {
+ return false;
+ }
+ final Geopoint gp = (Geopoint) obj;
+ return getLatitudeE6() == gp.getLatitudeE6() && getLongitudeE6() == gp.getLongitudeE6();
+ }
+
+ @Override
+ public int hashCode() {
+ return getLatitudeE6() ^ getLongitudeE6();
}
/**