![JAR search and dependency download from the Maven repository](/logo.png)
com.skylarwatson.blinky.internal.factory.UsbHubFactory Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of blinky Show documentation
Show all versions of blinky Show documentation
Java API for interacting with blink(1) USB
The newest version!
package com.skylarwatson.blinky.internal.factory;
import com.skylarwatson.blinky.internal.UsbHostManagerAdapter;
import javax.usb.UsbDevice;
import javax.usb.UsbHub;
import javax.usb.UsbPort;
import java.util.List;
import java.util.stream.Stream;
import static java.util.stream.Collectors.toList;
public class UsbHubFactory {
private UsbHostManagerAdapter adapter = new UsbHostManagerAdapter();
public List create() {
List ports = adapter.getUsbPorts();
return Stream.concat(
devicesNotFoundOnHub(ports),
devicesFoundOnHub(ports)
).collect(toList());
}
private Stream devicesFoundOnHub(List portStream) {
return portStream.stream().filter(port -> port.getUsbDevice().isUsbHub())
.map(port -> (UsbHub) port.getUsbDevice())
.map(device -> (List) device.getAttachedUsbDevices())
.flatMap(List::stream);
}
private Stream devicesNotFoundOnHub(List portStream) {
return portStream.stream()
.filter(port -> !port.getUsbDevice().isUsbHub())
.map(UsbPort::getUsbDevice);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy