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

com.zhaofujun.automapper.converter.ConverterManager Maven / Gradle / Ivy

There is a newer version: 1.3.7
Show newest version
package com.zhaofujun.automapper.converter;

import java.util.ArrayList;
import java.util.List;

public class ConverterManager {

    private List converters = new ArrayList<>();


    public ConverterInfo getConverter(Class sourceClass, Class targetClass) {
        Converter converter = converters.stream()
                .filter(p -> (sourceClass.isAssignableFrom( p.getSourceClass())&& targetClass.isAssignableFrom(p.getTargetClass()))
                        ||
                        (targetClass.isAssignableFrom(p.getSourceClass()) && sourceClass.isAssignableFrom(p.getTargetClass()))
                )
                .findFirst()
                .orElse(null);
        if (converter == null) return null;
        if (converter.getTargetClass().equals(targetClass))
            return new ConverterInfo(converter, ConverterInfo.Direction.positive);
        else
            return new ConverterInfo(converter, ConverterInfo.Direction.negative);
    }

    public void addConverter(Converter converter) {
        converters.add(converter);
    }
}






© 2015 - 2025 Weber Informatics LLC | Privacy Policy