// Path: src/main/java/de/wellnerbou/chronic/logparser/LogLineParser.java
// public interface LogLineParser {
// 
// 	LogLineData parseLine(Object logLine);
// 	String getId();
// }


import de.wellnerbou.chronic.logparser.LogLineParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;
package de.wellnerbou.chronic.plugins;



public abstract class ServiceLoaderImplementationProvider<T> {

	private ServiceLoader<T> serviceLoader;
	private static final Logger LOG = LoggerFactory.getLogger(ServiceLoaderImplementationProvider.class);

	public ServiceLoaderImplementationProvider() {
		this.load();
	}

	private void load() {
		serviceLoader = ServiceLoader.load(getImplementationClass());
	}

	public T getImplementation(final String id) {
		List<T> list = getAllImplementations(id);
		if (list.isEmpty()) {
			throw new NoImplementationFoundException(getImplementationClass(), id);
		} else if (list.size() > 1) {
// Path: src/main/java/de/wellnerbou/chronic/logparser/LogLineParser.java
// public interface LogLineParser {
// 
// 	LogLineData parseLine(Object logLine);
// 	String getId();
// }


// Path: src/main/java/de/wellnerbou/chronic/plugins/ServiceLoaderImplementationProvider.java
import de.wellnerbou.chronic.logparser.LogLineParser;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.util.ArrayList;
import java.util.List;
import java.util.ServiceLoader;

package de.wellnerbou.chronic.plugins;



public abstract class ServiceLoaderImplementationProvider<T> {

	private ServiceLoader<T> serviceLoader;
	private static final Logger LOG = LoggerFactory.getLogger(ServiceLoaderImplementationProvider.class);

	public ServiceLoaderImplementationProvider() {
		this.load();
	}

	private void load() {
		serviceLoader = ServiceLoader.load(getImplementationClass());
	}

	public T getImplementation(final String id) {
		List<T> list = getAllImplementations(id);
		if (list.isEmpty()) {
			throw new NoImplementationFoundException(getImplementationClass(), id);
		} else if (list.size() > 1) {
			LOG.warn("More than one implementations for {} with id {} found, using first one: {}", LogLineParser.class.getName(), id, list.get(0).getClass().getName());