From 91bb344a74a413f7dcee379c4d760c34599749bc Mon Sep 17 00:00:00 2001 From: Keith Packard Date: Wed, 22 Aug 2018 00:53:46 -0700 Subject: [PATCH] altosuilib: Add 'equals' method to AltosDevice Signed-off-by: Keith Packard --- altosuilib/AltosDevice.java | 1 + altosuilib/AltosUSBDevice.java | 17 +++++++++++++++++ 2 files changed, 18 insertions(+) diff --git a/altosuilib/AltosDevice.java b/altosuilib/AltosDevice.java index 483d337b..a5a068b4 100644 --- a/altosuilib/AltosDevice.java +++ b/altosuilib/AltosDevice.java @@ -28,4 +28,5 @@ public interface AltosDevice { public abstract boolean matchProduct(int product); public abstract String getErrorString(); public SWIGTYPE_p_altos_file open(); + public abstract boolean equals(Object obj); } diff --git a/altosuilib/AltosUSBDevice.java b/altosuilib/AltosUSBDevice.java index f7aae38a..16a0e770 100644 --- a/altosuilib/AltosUSBDevice.java +++ b/altosuilib/AltosUSBDevice.java @@ -94,6 +94,23 @@ public class AltosUSBDevice extends altos_device implements AltosDevice { return false; } + public int hashCode() { + return getVendor() ^ getProduct() ^ getSerial(); + } + + public boolean equals(Object o) { + if (o == null) + return false; + + if (!(o instanceof AltosUSBDevice)) + return false; + AltosUSBDevice other = (AltosUSBDevice) o; + + return getVendor() == other.getVendor() && + getProduct() == other.getProduct() && + getSerial() == other.getSerial(); + } + static public java.util.List list(int product) { if (!AltosUILib.load_library()) return null; -- 2.30.2