断言类
public final class Assert { private Assert() { } public static void notNull(Object object) { if (object == null) { throw new ApiRuntimeException(ErrorCode.SYSTEM_PARAM_ERROR_IS_NULL); } } public static void notNull(Object... object) { for (Object obj : object) { if (obj == null) { throw new ApiRuntimeException(ErrorCode.SYSTEM_PARAM_ERROR_IS_NULL); } } } public static void isPositive(Long number) { if (number == null || number <= 0) { throw new ApiRuntimeException(ErrorCode.SYSTEM_PARAM_ERROR); } } public static void isPositive(Long... number) { for (Long num : number) { if (num == null || num <= 0) { throw new ApiRuntimeException(ErrorCode.SYSTEM_PARAM_ERROR); } } } public static void isPositive(Integer number) { if (number == null || number <= 0) { throw new ApiRuntimeException(ErrorCode.SYSTEM_PARAM_ERROR); } } public static void isPositive(Integer... number) { for (Integer num : number) { if (num == null || num <= 0) { throw new ApiRuntimeException(ErrorCode.SYSTEM_PARAM_ERROR); } } } public static void notEmpty(String str, ErrorCode errorCode) { if (StringUtils.isEmpty(str)) { throw new ApiRuntimeException(errorCode); } } public static void notBlank(String str, ErrorCode errorCode) { if (StringUtils.isBlank(str)) { throw new ApiRuntimeException(errorCode); } } public static void isTrue(boolean condition, ErrorCode errorCode) { if (!condition) { throw new ApiRuntimeException(errorCode); } } }
断言类,用来在业务类之前判断参数。