com.jn.agileway.spring.converter.CommonEnumByNameConverterFactory Maven / Gradle / Ivy
package com.jn.agileway.spring.converter;
import com.jn.langx.registry.Registry;
import com.jn.langx.util.enums.base.CommonEnum;
import org.springframework.core.convert.converter.Converter;
import org.springframework.core.convert.converter.ConverterFactory;
import java.util.concurrent.ConcurrentHashMap;
public class CommonEnumByNameConverterFactory implements Registry>, ConverterFactory {
private ConcurrentHashMap> cache;
public CommonEnumByNameConverterFactory(){
this.cache= new ConcurrentHashMap<>();
}
@Override
public void register(Converter stringTConverter) {
// noop
}
@Override
public void register(Class enumClass, Converter stringTConverter) {
cache.put(enumClass, stringTConverter);
}
@Override
public Converter get(Class enumClass) {
return cache.get(enumClass);
}
@Override
public void unregister(Class key) {
cache.remove(key);
}
@Override
public boolean contains(Class key) {
return cache.containsKey(key);
}
@Override
public Converter getConverter(Class targetType) {
if (targetType.isEnum()) {
Converter converter = get(targetType);
if (converter == null) {
converter = new NameToCommonEnumConverter<>(targetType);
register(targetType, converter);
}
}
return null;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy