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

org.simpleflatmapper.reflect.meta.AliasProviderService Maven / Gradle / Ivy

Go to download

Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.

There is a newer version: 9.0.2
Show newest version
package org.simpleflatmapper.reflect.meta;


import org.simpleflatmapper.util.Consumer;
import org.simpleflatmapper.util.ProducerServiceLoader;

import java.util.ArrayList;
import java.util.ServiceLoader;

public final class AliasProviderService {

	private AliasProviderService() { }

	private static final AliasProvider aliasProvider = findAliasProviders();


	private static AliasProvider findAliasProviders() {
		final ArrayList providers = new ArrayList();

		ProducerServiceLoader.produceFromServiceLoader(ServiceLoader.load(AliasProviderProducer.class), new Consumer() {
			@Override
			public void accept(AliasProvider t) {
				providers.add(t);
			}
		});
		return aggregateAliasProvider(providers.toArray(new AliasProvider[0]));
	}

	public static AliasProvider getAliasProvider() {
		return aliasProvider;
	}

	private static AliasProvider aggregateAliasProvider(AliasProvider[] registered) {
		if (registered.length == 0) {
			return new DefaultAliasProvider();
		} else if (registered.length == 1) {
			return registered[0];
		} else {
			return new ArrayAliasProvider(registered);
		}
	}

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy