Implement equals/hashCode for ControlSetup by comparing the two buffers fully (only thing you can do!).
Change equals/hashCode for IsoPacketDescriptor and related Transfer to use only their pointers to native memory. This is because two Transfers may be the same on all accounts, but they still are not the same Transfer that's happening. Also it interfered with removal of Transfers from a list in the callback: Java couldn't clearly distinguish them and started accessing members of some that were already freed, resulting in exceptions. Furhter, implement toString for IsoPacketDescriptor, Transfer and ControlSetup.
This commit is contained in:
parent
f92a84c979
commit
09d582157f
@ -81,4 +81,51 @@ public final class ControlSetup
|
||||
{
|
||||
controlSetup.putShort(6, wLength);
|
||||
}
|
||||
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = (prime * result)
|
||||
+ ((controlSetup == null) ? 0 : controlSetup.hashCode());
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(final Object obj)
|
||||
{
|
||||
if (this == obj)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
if (obj == null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
if (getClass() != obj.getClass())
|
||||
{
|
||||
return false;
|
||||
}
|
||||
final ControlSetup other = (ControlSetup) obj;
|
||||
if (controlSetup == null)
|
||||
{
|
||||
if (other.controlSetup != null)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
else if (!controlSetup.equals(other.controlSetup))
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("libusb control setup with buffer %s",
|
||||
controlSetup.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@ -1,8 +1,5 @@
|
||||
package de.ailis.usb4java.libusb;
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
|
||||
public final class IsoPacketDescriptor
|
||||
{
|
||||
/** The native pointer to the descriptor structure. */
|
||||
@ -41,11 +38,11 @@ public final class IsoPacketDescriptor
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return new HashCodeBuilder()
|
||||
.append(length())
|
||||
.append(actualLength())
|
||||
.append(status())
|
||||
.toHashCode();
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = (prime * result)
|
||||
+ (int) (isoPacketDescriptorPointer ^ (isoPacketDescriptorPointer >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -63,13 +60,18 @@ public final class IsoPacketDescriptor
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final IsoPacketDescriptor other = (IsoPacketDescriptor) obj;
|
||||
if (isoPacketDescriptorPointer != other.isoPacketDescriptorPointer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return new EqualsBuilder()
|
||||
.append(length(), other.length())
|
||||
.append(actualLength(), other.actualLength())
|
||||
.append(status(), other.status())
|
||||
.isEquals();
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("libusb iso packet descriptor 0x%x",
|
||||
isoPacketDescriptorPointer);
|
||||
}
|
||||
}
|
||||
|
||||
@ -13,9 +13,6 @@ package de.ailis.usb4java.libusb;
|
||||
|
||||
import java.nio.ByteBuffer;
|
||||
|
||||
import org.apache.commons.lang3.builder.EqualsBuilder;
|
||||
import org.apache.commons.lang3.builder.HashCodeBuilder;
|
||||
|
||||
/**
|
||||
* The generic USB transfer structure.
|
||||
*
|
||||
@ -193,7 +190,6 @@ public final class Transfer
|
||||
*/
|
||||
public native int actualLength();
|
||||
|
||||
|
||||
/**
|
||||
* Returns the current callback object.
|
||||
*
|
||||
@ -291,21 +287,11 @@ public final class Transfer
|
||||
@Override
|
||||
public int hashCode()
|
||||
{
|
||||
return new HashCodeBuilder()
|
||||
.append(devHandle())
|
||||
.append(flags())
|
||||
.append(endpoint())
|
||||
.append(type())
|
||||
.append(timeout())
|
||||
.append(status())
|
||||
.append(length())
|
||||
.append(actualLength())
|
||||
.append(callback())
|
||||
.append(userData())
|
||||
.append(buffer())
|
||||
.append(numIsoPackets())
|
||||
.append(isoPacketDesc())
|
||||
.toHashCode();
|
||||
final int prime = 31;
|
||||
int result = 1;
|
||||
result = (prime * result)
|
||||
+ (int) (transferPointer ^ (transferPointer >>> 32));
|
||||
return result;
|
||||
}
|
||||
|
||||
@Override
|
||||
@ -323,23 +309,17 @@ public final class Transfer
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
final Transfer other = (Transfer) obj;
|
||||
if (transferPointer != other.transferPointer)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
return new EqualsBuilder()
|
||||
.append(devHandle(), other.devHandle())
|
||||
.append(flags(), other.flags())
|
||||
.append(endpoint(), other.endpoint())
|
||||
.append(type(), other.type())
|
||||
.append(timeout(), other.timeout())
|
||||
.append(status(), other.status())
|
||||
.append(length(), other.length())
|
||||
.append(actualLength(), other.actualLength())
|
||||
.append(callback(), other.callback())
|
||||
.append(userData(), other.userData())
|
||||
.append(buffer(), other.buffer())
|
||||
.append(numIsoPackets(), other.numIsoPackets())
|
||||
.append(isoPacketDesc(), other.isoPacketDesc())
|
||||
.isEquals();
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
return String.format("libusb transfer 0x%x", transferPointer);
|
||||
}
|
||||
}
|
||||
|
||||
Loading…
Reference in New Issue
Block a user