|
@@ -1,184 +0,0 @@
|
|
|
-/*
|
|
|
- * 文 件 名: Assert
|
|
|
- * 版 权: 浩鲸云计算科技股份有限公司
|
|
|
- * 描 述: <描述>
|
|
|
- * 修 改 人: lv.wenbin@huashe.com
|
|
|
- * 修改时间: 2019/4/21
|
|
|
- */
|
|
|
-package com.huashe.citybrain.commons.base.exception;
|
|
|
-
|
|
|
-import java.util.Collection;
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
-/**
|
|
|
- * 断言 <功能详细描述>
|
|
|
- *
|
|
|
- * @author lv.wenbin@huashe.com
|
|
|
- * @version [版本号, 2019/4/21]
|
|
|
- * @see [相关类/方法]
|
|
|
- * @since [产品/模块版本]
|
|
|
- */
|
|
|
-public abstract class Assert {
|
|
|
- /**
|
|
|
- * 真假断言 <功能详细描述>
|
|
|
- *
|
|
|
- * @param expression 真假
|
|
|
- * @param errorCode 错误码
|
|
|
- * @param message 错误消息
|
|
|
- * @throws BusinessException 异常
|
|
|
- * @see [类、类#方法、类#成员]
|
|
|
- */
|
|
|
- public static void isTrue(boolean expression, int errorCode, String message) throws BusinessException {
|
|
|
- if (!expression) {
|
|
|
- throw new BusinessException(errorCode, message);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 真假断言 <功能详细描述>
|
|
|
- *
|
|
|
- * @param expression 真假
|
|
|
- * @param errorCode 错误码
|
|
|
- * @throws BusinessException 异常
|
|
|
- * @see [类、类#方法、类#成员]
|
|
|
- */
|
|
|
- public static void isTrue(boolean expression, ErrorCode errorCode) throws BusinessException {
|
|
|
- if (!expression) {
|
|
|
- throw new BusinessException(errorCode.getCode(), errorCode.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 真假断言 <功能详细描述>
|
|
|
- *
|
|
|
- * @param expression 真假
|
|
|
- * @param errorCode 错误码
|
|
|
- * @param message 错误消息
|
|
|
- * @param ext 扩展属性
|
|
|
- * @throws BusinessException 异常
|
|
|
- * @see [类、类#方法、类#成员]
|
|
|
- */
|
|
|
- public static void isTrue(boolean expression, int errorCode, String message, Object ext) throws BusinessException {
|
|
|
- if (!expression) {
|
|
|
- throw new BusinessException(errorCode, message, ext);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 空判断 <功能详细描述>
|
|
|
- *
|
|
|
- * @param object 对象
|
|
|
- * @param errorCode 错误码
|
|
|
- * @param message 错误消息
|
|
|
- * @throws BusinessException 异常
|
|
|
- * @see [类、类#方法、类#成员]
|
|
|
- */
|
|
|
- public static void isNull(Object object, int errorCode, String message) throws BusinessException {
|
|
|
- if (object != null) {
|
|
|
- throw new BusinessException(errorCode, message);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 空判断 <功能详细描述>
|
|
|
- *
|
|
|
- * @param object 对象
|
|
|
- * @param errorCode 错误
|
|
|
- * @throws BusinessException 异常
|
|
|
- * @see [类、类#方法、类#成员]
|
|
|
- */
|
|
|
- public static void isNull(Object object, ErrorCode errorCode) throws BusinessException {
|
|
|
- if (object != null) {
|
|
|
- throw new BusinessException(errorCode.getCode(), errorCode.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 非空判断 <功能详细描述>
|
|
|
- *
|
|
|
- * @param object 对象
|
|
|
- * @param errorCode 错误码
|
|
|
- * @param message 错误消息
|
|
|
- * @throws BusinessException 异常
|
|
|
- * @see [类、类#方法、类#成员]
|
|
|
- */
|
|
|
- public static void notNull(Object object, int errorCode, String message) throws BusinessException {
|
|
|
- if (object == null) {
|
|
|
- throw new BusinessException(errorCode, message);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 非空判断 <功能详细描述>
|
|
|
- *
|
|
|
- * @param object 对象
|
|
|
- * @param errorCode 错误
|
|
|
- * @throws BusinessException 异常
|
|
|
- * @see [类、类#方法、类#成员]
|
|
|
- */
|
|
|
- public static void notNull(Object object, ErrorCode errorCode) throws BusinessException {
|
|
|
- if (object == null) {
|
|
|
- throw new BusinessException(errorCode.getCode(), errorCode.getMessage());
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 数组非空判断 <功能详细描述>
|
|
|
- *
|
|
|
- * @param array 数组
|
|
|
- * @param errorCode 错误码
|
|
|
- * @param message 错误消息
|
|
|
- * @throws BusinessException 异常
|
|
|
- * @see [类、类#方法、类#成员]
|
|
|
- */
|
|
|
- public static void notEmpty(Object[] array, int errorCode, String message) throws BusinessException {
|
|
|
- if (array == null || array.length == 0) {
|
|
|
- throw new BusinessException(errorCode, message);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 集合非空判断 <功能详细描述>
|
|
|
- *
|
|
|
- * @param collection 集合列表
|
|
|
- * @param errorCode 错误码
|
|
|
- * @param message 错误信息
|
|
|
- * @throws BusinessException 异常
|
|
|
- * @see [类、类#方法、类#成员]
|
|
|
- */
|
|
|
- public static <T> void notEmpty(Collection<T> collection, int errorCode, String message) throws BusinessException {
|
|
|
- if (collection == null || collection.isEmpty()) {
|
|
|
- throw new BusinessException(errorCode, message);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * Map非空判断
|
|
|
- *
|
|
|
- * @param map Map Map集合
|
|
|
- * @param errorCode 错误码
|
|
|
- * @param message 错误信息
|
|
|
- * @throws BusinessException 异常
|
|
|
- * @see [类、类#方法、类#成员]
|
|
|
- */
|
|
|
- public static <K, V> void notEmpty(Map<K, V> map, int errorCode, String message) throws BusinessException {
|
|
|
- if (map == null || map.isEmpty()) {
|
|
|
- throw new BusinessException(errorCode, message);
|
|
|
- }
|
|
|
- }
|
|
|
-
|
|
|
- /**
|
|
|
- * 字符串空判断 <功能详细描述>
|
|
|
- *
|
|
|
- * @param str 字符串
|
|
|
- * @param errorCode 错误码
|
|
|
- * @param message 错误信息
|
|
|
- * @throws BusinessException 异常
|
|
|
- * @see [类、类#方法、类#成员]
|
|
|
- */
|
|
|
- public static void notEmpty(String str, int errorCode, String message) throws BusinessException {
|
|
|
- if (str == null || str.length() == 0) {
|
|
|
- throw new BusinessException(errorCode, message);
|
|
|
- }
|
|
|
- }
|
|
|
-}
|