altosuilib: Add 'equals' method to AltosDevice
authorKeith Packard <keithp@keithp.com>
Wed, 22 Aug 2018 07:53:46 +0000 (00:53 -0700)
committerKeith Packard <keithp@keithp.com>
Wed, 22 Aug 2018 08:01:46 +0000 (01:01 -0700)
Signed-off-by: Keith Packard <keithp@keithp.com>
altosuilib/AltosDevice.java
altosuilib/AltosUSBDevice.java

index 483d337b142fa63fbdecc8aac0c02db284a70767..a5a068b4d95f2eef7d7694c43b425f195558a2c5 100644 (file)
@@ -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);
 }
index f7aae38a3ab6bac3468da539217b4393628a3067..16a0e7709dd5be7c3793bd3eb42c86c481164d6c 100644 (file)
@@ -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<AltosDevice> list(int product) {
                if (!AltosUILib.load_library())
                        return null;