org.simpleflatmapper.map.property.SetterProperty 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.Setter;
import org.simpleflatmapper.util.TypeHelper;
import java.lang.reflect.Type;
public class SetterProperty {
private final Setter, ?> setter;
private final Type targetType;
private final Type propertyType;
public SetterProperty(Setter, ?> setter) {
this(setter, getTargetType(setter), getPropertyType(setter));
}
public SetterProperty(Setter, ?> setter, Type targetType, Type propertyType) {
this.setter = setter;
this.targetType = targetType;
this.propertyType = propertyType;
}
public Setter, ?> getSetter() {
return setter;
}
public Type getTargetType() {
return targetType;
}
@Override
public String toString() {
return "Setter{" + setter + "}";
}
private static Type getTargetType(Setter, ?> setter) {
Type[] types = TypeHelper.getGenericParameterForClass(setter.getClass(), Setter.class);
return types != null ? types[0] : null;
}
private static Type getPropertyType(Setter, ?> setter) {
Type[] types = TypeHelper.getGenericParameterForClass(setter.getClass(), Setter.class);
return types != null ? types[1] : null;
}
public Type getPropertyType() {
return propertyType;
}
}