uk.dioxic.mgenerate.common.TransformerRegistry Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mgenerate-common Show documentation
Show all versions of mgenerate-common Show documentation
Common code for mgenerate4j
The newest version!
package uk.dioxic.mgenerate.common;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import uk.dioxic.mgenerate.common.annotation.ValueTransformer;
import java.util.HashMap;
import java.util.Map;
public class TransformerRegistry {
private final Logger logger = LoggerFactory.getLogger(getClass());
private final Map transformerMap = new HashMap<>();
public void addTransformer(Transformer transformer) {
ValueTransformer annotation = transformer.getClass().getAnnotation(ValueTransformer.class);
logger.debug("adding [{}] to transformer registry", annotation.value());
transformerMap.put(annotation.value(), transformer);
}
@SuppressWarnings("unchecked")
public Transformer get(Class desiredClass) {
return (Transformer) transformerMap.get(desiredClass);
}
public boolean canHandle(Class desiredClass) {
return transformerMap.containsKey(desiredClass);
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy