org.simpleflatmapper.reflect.meta.AliasProviderService Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-reflect Show documentation
Show all versions of sfm-reflect Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
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);
}
}
}