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

org.simpleflatmapper.map.property.SetterProperty 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.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;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy