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

koncept.http.server.KnownProviders Maven / Gradle / Ivy

The newest version!
package koncept.http.server;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
import java.util.List;

import com.sun.net.httpserver.spi.HttpServerProvider;

public class KnownProviders {

	/**
	 * 
	 * @return the providers, all ready in JUnit format
	 */
	public static List providers() {
		return Arrays.asList(
				new sun.net.httpserver.DefaultHttpServerProvider(),
//				new koncept.http.KonceptHttpServerProvider(), //default provider stub
				new koncept.http.KonceptHttpIOServerProvider(),
				new koncept.http.KonceptHttpNIO2ServerProvider()
		);
	}
	
	public static List withHttps(Boolean b) {
		if (b != null) return Arrays.asList(b);
		return Arrays.asList(false, true);
	}
	
	/**
	 * 
	 * @return filtered providers, in JUnit format
	 */
	public static List configurableProviders() {
		return configurableProviders(providers());
	}
	
	public static List configurableProviders(Collection providers) {
		List configurableProviders = new ArrayList<>();
		for(HttpServerProvider provider: providers) {
			if (provider instanceof ConfigurableHttpServerProvider)
				configurableProviders.add((ConfigurableHttpServerProvider)provider);
		}
		return configurableProviders;
	}
	

	public static Collection junitJoin(Collection... allJunitParams) {
		if (allJunitParams.length == 0) throw new IllegalArgumentException();		
		return junitJoin(new ArrayList(), allJunitParams[0], tail(allJunitParams));
	}
	
	private static Collection[] tail(Collection... allJunitParams) {
		if (allJunitParams.length == 0) return null;
		Collection[] tail = new Collection[allJunitParams.length - 1];
		System.arraycopy(allJunitParams, 1, tail, 0, tail.length);
		return tail;
	}
	private static Collection head(Collection... allJunitParams) {
		if (allJunitParams.length == 0) return null;
		return allJunitParams[0];
	}
	private static Collection junitJoin(List currentRow, Collection head, Collection... tail) {
		Collection joined = new ArrayList<>();
		if (head != null) {
			for(Object junitParam: head) {
				List row = new ArrayList<>(currentRow);
				row.add(junitParam);
				joined.addAll(junitJoin(row, head(tail), tail(tail)));
			}
		} else {
			joined.add(currentRow.toArray());
		}
		return joined;
	}
	
}




© 2015 - 2025 Weber Informatics LLC | Privacy Policy