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

org.simpleflatmapper.reflect.getter.GetterFactoryRegistry 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.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);
    }
    
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy