From 0cc03210d5d53d12604688f294b6ca39e3a025de Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Sat, 20 Jun 2015 09:35:26 -0700 Subject: altoslib/altosuilib: Fix equals methods, add hashCode Whenever we use a class as a HashMap key, that class needs to override the equals(Object) and hashCode() methods. Otherwise, the hash table won't work right. Signed-off-by: Keith Packard --- altoslib/AltosMapPathPoint.java | 13 +++++++++++-- 1 file changed, 11 insertions(+), 2 deletions(-) (limited to 'altoslib/AltosMapPathPoint.java') diff --git a/altoslib/AltosMapPathPoint.java b/altoslib/AltosMapPathPoint.java index 9f82f02a..0d54744a 100644 --- a/altoslib/AltosMapPathPoint.java +++ b/altoslib/AltosMapPathPoint.java @@ -26,10 +26,19 @@ public class AltosMapPathPoint { public AltosLatLon lat_lon; public int state; - public boolean equals(AltosMapPathPoint other) { - if (other == null) + public int hashCode() { + return lat_lon.hashCode() ^ state; + } + + public boolean equals(Object o) { + if (o == null) return false; + if (!(o instanceof AltosMapPathPoint)) + return false; + + AltosMapPathPoint other = (AltosMapPathPoint) o; + return lat_lon.equals(other.lat_lon) && state == other.state; } -- cgit v1.2.3