org.simpleflatmapper.map.property.GetterProperty Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of sfm-map Show documentation
Show all versions of sfm-map Show documentation
Java library to map flat record - ResultSet, csv - to java object with minimum configuration and low footprint.
package org.simpleflatmapper.map.property;
import org.simpleflatmapper.reflect.Getter;
import org.simpleflatmapper.util.TypeHelper;
import java.lang.reflect.Type;
public class GetterProperty {
private final Getter, ?> getter;
private final Type returnType;
private final Type sourceType;
public GetterProperty(Getter, ?> getter) {
this(getter, getSourceType(getter), getReturnType(getter));
}
public GetterProperty(Getter, ?> getter, Type sourceType, Type returnType) {
this.getter = getter;
this.returnType = returnType;
this.sourceType = sourceType;
}
public Type getReturnType() {
return returnType;
}
public Type getSourceType() {
return sourceType;
}
public Getter, ?> getGetter() {
return getter;
}
public String toString() {
return "Getter{" + getter + "}";
}
public static Type getReturnType(Getter, ?> getter) {
Type[] paramTypesForInterface = TypeHelper.getGenericParameterForClass(getter.getClass(), Getter.class);
return paramTypesForInterface != null ? paramTypesForInterface[1] : null;
}
public static Type getSourceType(Getter, ?> getter) {
Type[] paramTypesForInterface = TypeHelper.getGenericParameterForClass(getter.getClass(), Getter.class);
return paramTypesForInterface != null ? paramTypesForInterface[0] : null;
}
}