org.simpleflatmapper.reflect.getter.GetterFactoryRegistry 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.
The newest version!
package org.simpleflatmapper.reflect.getter;
import org.simpleflatmapper.util.TypeHelper;
import java.lang.reflect.Type;
import java.math.BigDecimal;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
public class GetterFactoryRegistry {
private final Map, GetterFactory> factoryPerType =
new HashMap, GetterFactory>();
public final void put(Class> target, GetterFactory getterFactory ){
factoryPerType.put(target, getterFactory);
}
public final GetterFactory findFactoryFor(Type targetType) {
Class> target = TypeHelper.toClass(targetType);
GetterFactory getterFactory = factoryPerType.get(target);
if (getterFactory != null) {
return getterFactory;
}
return null;
}
public void mapFromTo(Class> target, Class> source) {
GetterFactory getterFactory = factoryPerType.get(source);
if (getterFactory == null) throw new IllegalStateException("No getter factory defined for " + source);
put(target, getterFactory);
}
}