de.mklinger.qetcher.client.impl.lookup.StaticServiceUriSupplier Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of qetcher-client-bundle Show documentation
Show all versions of qetcher-client-bundle Show documentation
Qetcher Java client, OSGi bundle, minimal dependencies
package de.mklinger.qetcher.client.impl.lookup;
import java.net.URI;
import java.util.List;
import java.util.concurrent.ThreadLocalRandom;
/**
* @author Marc Klinger - mklinger[at]mklinger[dot]de
*/
public class StaticServiceUriSupplier implements ServiceUriSupplier {
private final List serviceUris;
public StaticServiceUriSupplier(final List serviceUris) {
this.serviceUris = requireNonEmpty(serviceUris);
}
private static List requireNonEmpty(final List l) {
if (l == null || l.isEmpty()) {
throw new IllegalArgumentException();
}
return l;
}
@Override
public URI get() {
final int randomIdx = ThreadLocalRandom.current()
.nextInt(serviceUris.size());
return serviceUris.get(randomIdx);
}
}
© 2015 - 2024 Weber Informatics LLC | Privacy Policy