summaryrefslogtreecommitdiff
path: root/altoslib/AltosPointInt.java
diff options
context:
space:
mode:
authorKeith Packard <keithp@keithp.com>2015-06-20 09:35:26 -0700
committerKeith Packard <keithp@keithp.com>2015-06-22 21:04:43 -0700
commit0cc03210d5d53d12604688f294b6ca39e3a025de (patch)
tree9bbe8895ef8d84502bec6b73c71299131b1c1b5b /altoslib/AltosPointInt.java
parent5568c30f0a4fe346b8ed58934c23653064427d65 (diff)
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 <keithp@keithp.com>
Diffstat (limited to 'altoslib/AltosPointInt.java')
-rw-r--r--altoslib/AltosPointInt.java14
1 files changed, 13 insertions, 1 deletions
diff --git a/altoslib/AltosPointInt.java b/altoslib/AltosPointInt.java
index 5d884391..a7dd00f7 100644
--- a/altoslib/AltosPointInt.java
+++ b/altoslib/AltosPointInt.java
@@ -20,7 +20,19 @@ package org.altusmetrum.altoslib_7;
public class AltosPointInt {
public int x, y;
- public boolean equals(AltosPointInt n) {
+ public int hashCode() {
+ return x ^ y;
+ }
+
+ public boolean equals(Object o) {
+ if (o == null)
+ return false;
+
+ if (!(o instanceof AltosPointInt))
+ return false;
+
+ AltosPointInt n = (AltosPointInt) o;
+
return n.x == x && n.y == y;
}