diff --git a/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbConfigurationDescriptor.java b/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbConfigurationDescriptor.java index 59b5621..3878bc5 100644 --- a/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbConfigurationDescriptor.java +++ b/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbConfigurationDescriptor.java @@ -133,7 +133,8 @@ public final class SimpleUsbConfigurationDescriptor extends SimpleUsbDescriptor public int hashCode() { return new HashCodeBuilder() - .appendSuper(super.hashCode()) + .append(bDescriptorType()) + .append(bLength()) .append(this.bConfigurationValue) .append(this.bMaxPower) .append(this.bNumInterfaces) @@ -147,10 +148,13 @@ public final class SimpleUsbConfigurationDescriptor extends SimpleUsbDescriptor public boolean equals(final Object obj) { if (this == obj) return true; - if (!super.equals(obj)) return false; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; final SimpleUsbConfigurationDescriptor other = (SimpleUsbConfigurationDescriptor) obj; return new EqualsBuilder() + .append(bLength(), other.bLength()) + .append(bDescriptorType(), other.bDescriptorType()) .append(this.bConfigurationValue, other.bConfigurationValue) .append(this.bMaxPower, other.bMaxPower) .append(this.bNumInterfaces, other.bNumInterfaces) @@ -163,14 +167,17 @@ public final class SimpleUsbConfigurationDescriptor extends SimpleUsbDescriptor @Override public String toString() { - return String.format("Configuration Descriptor:%n%s" + return String.format("Configuration Descriptor:%n" + + " bLength %18d%n" + + " bDescriptorType %10d%n" + " wTotalLength %13d%n" + " bNumInterfaces %11d%n" + " bConfigurationValue %6d%n" + " iConfiguration %11d%n" + " bmAttributes %13s%n" + " bMaxPower %16smA%n", - super.toString(), + bLength(), + bDescriptorType(), this.wTotalLength & 0xffff, this.bNumInterfaces & 0xff, this.bConfigurationValue & 0xff, diff --git a/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbDescriptor.java b/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbDescriptor.java index 9c733b4..2fea038 100644 --- a/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbDescriptor.java +++ b/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbDescriptor.java @@ -9,8 +9,6 @@ import java.io.Serializable; import javax.usb.UsbDescriptor; -import org.apache.commons.lang3.builder.HashCodeBuilder; - /** * Base class for all simple USB descriptors. * @@ -53,33 +51,4 @@ public abstract class SimpleUsbDescriptor implements UsbDescriptor, { return this.bDescriptorType; } - - @Override - public int hashCode() - { - return new HashCodeBuilder() - .appendSuper(super.hashCode()) - .append(this.bDescriptorType) - .append(this.bLength) - .toHashCode(); - } - - @Override - public boolean equals(final Object obj) - { - if (this == obj) return true; - if (obj == null) return false; - if (getClass() != obj.getClass()) return false; - final SimpleUsbDescriptor other = (SimpleUsbDescriptor) obj; - if (this.bDescriptorType != other.bDescriptorType) return false; - if (this.bLength != other.bLength) return false; - return true; - } - - @Override - public String toString() - { - return String.format(" bLength %18d%n bDescriptorType %10d%n", - this.bLength, this.bDescriptorType); - } } diff --git a/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbDeviceDescriptor.java b/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbDeviceDescriptor.java index 581c17d..ad483f4 100644 --- a/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbDeviceDescriptor.java +++ b/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbDeviceDescriptor.java @@ -212,7 +212,8 @@ public final class SimpleUsbDeviceDescriptor extends SimpleUsbDescriptor public int hashCode() { return new HashCodeBuilder() - .appendSuper(super.hashCode()) + .append(bDescriptorType()) + .append(bLength()) .append(this.bDeviceClass) .append(this.bDeviceProtocol) .append(this.bDeviceSubClass) @@ -232,9 +233,12 @@ public final class SimpleUsbDeviceDescriptor extends SimpleUsbDescriptor public boolean equals(final Object obj) { if (this == obj) return true; - if (!super.equals(obj)) return false; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; final SimpleUsbDeviceDescriptor other = (SimpleUsbDeviceDescriptor) obj; return new EqualsBuilder() + .append(bLength(), other.bLength()) + .append(bDescriptorType(), other.bDescriptorType()) .append(this.bDeviceClass, other.bDeviceClass) .append(this.bDeviceProtocol, other.bDeviceProtocol) .append(this.bDeviceSubClass, other.bDeviceSubClass) @@ -253,7 +257,9 @@ public final class SimpleUsbDeviceDescriptor extends SimpleUsbDescriptor @Override public String toString() { - return String.format("Device Descriptor:%n%s" + return String.format("Device Descriptor:%n" + + " bLength %18d%n" + + " bDescriptorType %10d%n" + " bcdDevice %13x.%02x%n" + " bDeviceClass %13d%n" + " bDeviceSubClass %10d%n" @@ -266,7 +272,8 @@ public final class SimpleUsbDeviceDescriptor extends SimpleUsbDescriptor + " iProduct %17d%n" + " iSerial %18d%n" + " bNumConfigurations %7d%n", - super.toString(), + bLength(), + bDescriptorType(), (this.bcdUSB & 0xff00) >> 8, this.bcdUSB & 0xff, this.bDeviceClass & 0xff, this.bDeviceSubClass & 0xff, diff --git a/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbEndpointDescriptor.java b/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbEndpointDescriptor.java index 1c34dd4..517804a 100644 --- a/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbEndpointDescriptor.java +++ b/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbEndpointDescriptor.java @@ -105,7 +105,8 @@ public final class SimpleUsbEndpointDescriptor extends SimpleUsbDescriptor public int hashCode() { return new HashCodeBuilder() - .appendSuper(super.hashCode()) + .append(bDescriptorType()) + .append(bLength()) .append(this.bEndpointAddress) .append(this.bInterval) .append(this.bmAttributes) @@ -117,10 +118,13 @@ public final class SimpleUsbEndpointDescriptor extends SimpleUsbDescriptor public boolean equals(final Object obj) { if (this == obj) return true; - if (!super.equals(obj)) return false; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; final SimpleUsbEndpointDescriptor other = (SimpleUsbEndpointDescriptor) obj; return new EqualsBuilder() + .append(bLength(), other.bLength()) + .append(bDescriptorType(), other.bDescriptorType()) .append(this.bEndpointAddress, other.bEndpointAddress) .append(this.bInterval, other.bInterval) .append(this.bmAttributes, other.bmAttributes) @@ -131,12 +135,15 @@ public final class SimpleUsbEndpointDescriptor extends SimpleUsbDescriptor @Override public String toString() { - return String.format("Endpoint Descriptor:%n%s" + return String.format("Endpoint Descriptor:%n" + + " bLength %18d%n" + + " bDescriptorType %10d%n" + " bEndpointAddress %9s%n" + " bmAttributes %13d%n" + " wMaxPacketSize %11d%n" + " bInterval %16d%n", - super.toString(), + bLength(), + bDescriptorType(), String.format("0x%02x", this.bEndpointAddress & 0xff), this.bmAttributes & 0xff, this.wMaxPacketSize & 0xffff, diff --git a/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbInterfaceDescriptor.java b/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbInterfaceDescriptor.java index ddf7b2e..cf73c0f 100644 --- a/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbInterfaceDescriptor.java +++ b/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbInterfaceDescriptor.java @@ -145,7 +145,8 @@ public final class SimpleUsbInterfaceDescriptor extends SimpleUsbDescriptor public int hashCode() { return new HashCodeBuilder() - .appendSuper(super.hashCode()) + .append(bDescriptorType()) + .append(bLength()) .append(this.bAlternateSetting) .append(this.bInterfaceClass) .append(this.bInterfaceNumber) @@ -160,10 +161,13 @@ public final class SimpleUsbInterfaceDescriptor extends SimpleUsbDescriptor public boolean equals(final Object obj) { if (this == obj) return true; - if (!super.equals(obj)) return false; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; final SimpleUsbInterfaceDescriptor other = (SimpleUsbInterfaceDescriptor) obj; return new EqualsBuilder() + .append(bLength(), other.bLength()) + .append(bDescriptorType(), other.bDescriptorType()) .append(this.bAlternateSetting, other.bAlternateSetting) .append(this.bInterfaceClass, other.bInterfaceClass) .append(this.bInterfaceNumber, other.bInterfaceNumber) @@ -177,7 +181,9 @@ public final class SimpleUsbInterfaceDescriptor extends SimpleUsbDescriptor @Override public String toString() { - return String.format("Interface Descriptor:%n%s" + return String.format("Interface Descriptor:%n" + + " bLength %18d%n" + + " bDescriptorType %10d%n" + " bInterfaceNumber %9d%n" + " bAlternateSetting %8d%n" + " bNumEndpoints %12d%n" @@ -185,7 +191,8 @@ public final class SimpleUsbInterfaceDescriptor extends SimpleUsbDescriptor + " bInterfaceSubClass %7d%n" + " bInterfaceProtocol %7d%n" + " iInterface %15d%n", - super.toString(), + bLength(), + bDescriptorType(), this.bInterfaceNumber & 0xff, this.bAlternateSetting & 0xff, this.bNumEndpoints & 0xff, diff --git a/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbStringDescriptor.java b/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbStringDescriptor.java index a55b476..4c179e6 100644 --- a/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbStringDescriptor.java +++ b/src/main/java/de/ailis/usb4java/descriptors/SimpleUsbStringDescriptor.java @@ -7,10 +7,12 @@ package de.ailis.usb4java.descriptors; import java.io.UnsupportedEncodingException; import java.nio.ByteBuffer; -import java.util.Arrays; import javax.usb.UsbStringDescriptor; +import org.apache.commons.lang3.builder.EqualsBuilder; +import org.apache.commons.lang3.builder.HashCodeBuilder; + /** * Simple string descriptor. * @@ -68,19 +70,24 @@ public final class SimpleUsbStringDescriptor extends SimpleUsbDescriptor public boolean equals(final Object obj) { if (this == obj) return true; - if (!super.equals(obj)) return false; + if (obj == null) return false; + if (getClass() != obj.getClass()) return false; final SimpleUsbStringDescriptor other = (SimpleUsbStringDescriptor) obj; - return Arrays.equals(this.bString, other.bString); + return new EqualsBuilder() + .append(bLength(), other.bLength()) + .append(bDescriptorType(), other.bDescriptorType()) + .append(this.bString, other.bString) + .isEquals(); } @Override public int hashCode() { - int result = 17; - result = 37 * result + bLength(); - result = 37 * result + bDescriptorType(); - result = 37 * result + Arrays.hashCode(this.bString); - return result; + return new HashCodeBuilder() + .append(bDescriptorType()) + .append(bLength()) + .append(this.bString) + .toHashCode(); } @Override