summaryrefslogtreecommitdiff
path: root/altosuilib/AltosBTDevice.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/AltosBTDevice.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/AltosBTDevice.java')
-rw-r--r--altosuilib/AltosBTDevice.java11
1 files changed, 7 insertions, 4 deletions
diff --git a/altosuilib/AltosBTDevice.java b/altosuilib/AltosBTDevice.java
index 76221df2..d6eed64d 100644
--- a/altosuilib/AltosBTDevice.java
+++ b/altosuilib/AltosBTDevice.java
@@ -104,17 +104,20 @@ public class AltosBTDevice extends altos_bt_device implements AltosDevice {
return false;
}
+ public int hashCode() {
+ return getName().hashCode() ^ getAddr().hashCode();
+ }
+
public boolean equals(Object o) {
+ if (o == null)
+ return false;
+
if (!(o instanceof AltosBTDevice))
return false;
AltosBTDevice other = (AltosBTDevice) o;
return getName().equals(other.getName()) && getAddr().equals(other.getAddr());
}
- public int hashCode() {
- return getName().hashCode() ^ getAddr().hashCode();
- }
-
public AltosBTDevice(String name, String addr) {
AltosUILib.load_library();
libaltos.altos_bt_fill_in(name, addr,this);