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

cn.featherfly.common.gentool.exception.util.ExceptionCodeCheck Maven / Gradle / Ivy

There is a newer version: 0.2.3
Show newest version

package cn.featherfly.common.gentool.exception.util;

import java.util.Collection;
import java.util.HashMap;
import java.util.Map;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import cn.featherfly.common.lang.ArrayUtils;

/**
 * 

* ExceptionCodeCheck *

* * @author zhongj */ public final class ExceptionCodeCheck { private static final ExceptionCodeCheck CHECK = new ExceptionCodeCheck(); protected final Logger logger = LoggerFactory.getLogger(this.getClass()); private ExceptionCodeCheck() { } Map> codes = new HashMap<>(0); private void checkCodeDuplicate(Class exceptionCodeType) { // Class codeEnumType = ClassUtils.forName( // exceptionCodeType.getName() + "$" + // GenExceptionCode.class.getSimpleName() + "s"); Class codeEnumType = exceptionCodeType.getClasses()[0]; for (Object e : codeEnumType.getEnumConstants()) { String code = e.toString(); logger.debug("check code {} declared in type {}", code, exceptionCodeType.getName()); Class t = codes.put(e.toString(), exceptionCodeType); if (t != null && t != exceptionCodeType) { throw new RuntimeException("duplicate code " + code + " declared in type " + exceptionCodeType.getName() + " " + t.getName()); } } } /** * checkCode * @param exceptionCodeType exceptionCodeType */ public static void checkCode(Class exceptionCodeType) { CHECK.checkCodeDuplicate(exceptionCodeType); } /** * checkCode * @param exceptionCodeTypes exceptionCodeTypes */ public static void checkCode(Collection> exceptionCodeTypes) { exceptionCodeTypes.forEach(e -> { checkCode(e); }); } /** * checkCode * @param exceptionCodeTypes exceptionCodeTypes */ public static void checkCode(Class[] exceptionCodeTypes) { checkCode(ArrayUtils.toList(exceptionCodeTypes)); } }




© 2015 - 2024 Weber Informatics LLC | Privacy Policy