All Downloads are FREE. Search and download functionalities are using the official Maven repository.

de.mklinger.qetcher.client.impl.lookup.StaticServiceUriSupplier Maven / Gradle / Ivy

There is a newer version: 2.0.42.rc
Show newest version
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