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

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

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy