org.usb4java.Interface Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of usb4java Show documentation
Show all versions of usb4java Show documentation
USB library for Java based on libusb and implementing javax-usb (JSR-80).
The newest version!
/*
* Copyright 2013 Klaus Reimer
* See LICENSE.md for licensing information.
*
* Based on libusb :
*
* Copyright 2001 Johannes Erdfelt
* Copyright 2007-2009 Daniel Drake
* Copyright 2010-2012 Peter Stuge
* Copyright 2008-2013 Nathan Hjelm
* Copyright 2009-2013 Pete Batard
* Copyright 2009-2013 Ludovic Rousseau
* Copyright 2010-2012 Michael Plante
* Copyright 2011-2013 Hans de Goede
* Copyright 2012-2013 Martin Pieuchot
* Copyright 2012-2013 Toby Gray
*/
package org.usb4java;
import org.apache.commons.lang3.builder.EqualsBuilder;
import org.apache.commons.lang3.builder.HashCodeBuilder;
/**
* A collection of alternate settings for a particular USB interface.
*
* @author Klaus Reimer ([email protected])
*/
public final class Interface
{
/** The native pointer to the descriptor structure. */
private long interfacePointer;
/**
* Package-private constructor to prevent manual instantiation. Interfaces
* are always created by JNI.
*/
Interface()
{
// Empty
}
/**
* Returns the native pointer.
*
* @return The native pointer.
*/
public long getPointer()
{
return this.interfacePointer;
}
/**
* Returns the array with interface descriptors. The length of this array is
* determined by the {@link #numAltsetting()} field.
*
* @return The array with interface descriptors.
*/
public native InterfaceDescriptor[] altsetting();
/**
* Returns the number of alternate settings that belong to this interface.
*
* @return The number of alternate settings.
*/
public native int numAltsetting();
/**
* Returns a dump of this interface.
*
* @return The interface dump.
*/
public String dump()
{
final StringBuilder builder = new StringBuilder();
builder.append(String.format(
"Interface:%n" +
" numAltsetting %10d",
this.numAltsetting()));
for (final InterfaceDescriptor intDesc : this.altsetting())
{
builder.append(String.format("%n") + intDesc.dump());
}
return builder.toString();
}
@Override
public int hashCode()
{
return new HashCodeBuilder()
.append(this.altsetting())
.append(this.numAltsetting())
.toHashCode();
}
@Override
public boolean equals(final Object obj)
{
if (this == obj)
{
return true;
}
if (obj == null)
{
return false;
}
if (this.getClass() != obj.getClass())
{
return false;
}
final Interface other = (Interface) obj;
return new EqualsBuilder()
.append(this.altsetting(), other.altsetting())
.append(this.numAltsetting(), other.numAltsetting())
.isEquals();
}
@Override
public String toString()
{
return this.dump();
}
}