summaryrefslogtreecommitdiff
path: root/altosuilib/AltosScanUI.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 /altosuilib/AltosScanUI.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 'altosuilib/AltosScanUI.java')
-rw-r--r--altosuilib/AltosScanUI.java13
1 files changed, 11 insertions, 2 deletions
diff --git a/altosuilib/AltosScanUI.java b/altosuilib/AltosScanUI.java
index 03115824..fccfbaee 100644
--- a/altosuilib/AltosScanUI.java
+++ b/altosuilib/AltosScanUI.java
@@ -62,9 +62,18 @@ class AltosScanResult {
rate = in_rate;
}
- public boolean equals(AltosScanResult other) {
+ public int hashCode() {
+ return serial ^ frequency.hashCode() ^ telemetry ^ rate;
+ }
+
+ public boolean equals(Object o) {
+ if (o == null)
+ return false;
+ if (!(o instanceof AltosScanResult))
+ return false;
+ AltosScanResult other = (AltosScanResult) o;
return (serial == other.serial &&
- frequency.frequency == other.frequency.frequency &&
+ frequency.equals(other.frequency) &&
telemetry == other.telemetry &&
rate == other.rate);
}