package com.huashe.park.common.animations.mybatis;

import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;

public class ConverterCache {
    private static final Map<Class<?>, Converter<?, ?>> cache = new ConcurrentHashMap<>();

    @SuppressWarnings("unchecked")
    public static <C extends Converter<?, ?>> C getConverter(Class<C> converterClass) {
        return (C) cache.computeIfAbsent(converterClass, clz -> {
            try {
                return (Converter<?, ?>) clz.getDeclaredConstructor().newInstance();
            }
            catch (Exception e) {
                throw new RuntimeException("Failed to create converter: " + clz.getName(), e);
            }
        });
    }
}
