org.usb4java.DeviceList 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 java.util.Iterator;
/**
* List of devices as returned by
* {@link LibUsb#getDeviceList(Context, DeviceList)}.
*
* @author Klaus Reimer ([email protected])
*/
public final class DeviceList implements Iterable
{
/** The native pointer to the devices array. */
private long deviceListPointer;
/** The number of devices in the list. */
private int size;
/**
* Constructs a new device list. Must be passed to
* {@link LibUsb#getDeviceList(Context, DeviceList)} before using it.
*/
public DeviceList()
{
// Empty
}
/**
* Returns the native pointer.
*
* @return The native pointer.
*/
public long getPointer()
{
return this.deviceListPointer;
}
/**
* Returns the number of devices in the list.
*
* @return The number of devices in the list.
*/
public int getSize()
{
return this.size;
}
/**
* Returns the device with the specified index.
*
* @param index
* The device index.
* @return The device or null when index is out of bounds.
*/
public native Device get(final int index);
@Override
public Iterator iterator()
{
return new DeviceListIterator(this);
}
@Override
public int hashCode()
{
final int prime = 31;
int result = 1;
result = (prime * result)
+ (int) (this.deviceListPointer ^ (this.deviceListPointer >>> 32));
return result;
}
@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 DeviceList other = (DeviceList) obj;
return this.deviceListPointer == other.deviceListPointer;
}
@Override
public String toString()
{
return String.format("libusb device list 0x%x with size %d",
this.deviceListPointer, this.size);
}
}