You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
163 lines
4.5 KiB
Java
163 lines
4.5 KiB
Java
2 years ago
|
package com.engine.junchuang.util;
|
||
|
|
||
|
import com.engine.junchuang.exception.OrganizationRunTimeException;
|
||
|
import org.springframework.util.CollectionUtils;
|
||
|
import org.springframework.util.ObjectUtils;
|
||
|
|
||
|
import java.util.Collection;
|
||
|
import java.util.Map;
|
||
|
|
||
|
/**
|
||
|
* @Author weaver_cl
|
||
|
* @description:
|
||
|
* @Date 2022/4/26
|
||
|
* @Version V1.0
|
||
|
**/
|
||
|
public abstract class OrganizationAssert {
|
||
|
/**
|
||
|
* 判断入参不为null
|
||
|
*
|
||
|
* @param object 待检查参数
|
||
|
* @param message 检查失败返回的异常信息
|
||
|
*/
|
||
|
public static void notNull(Object object, String message) {
|
||
|
if (object == null) {
|
||
|
throw new OrganizationRunTimeException(message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 判断多个入参不为null
|
||
|
*
|
||
|
* @param message 检查失败返回的异常信息
|
||
|
* @param objects 待检查参数
|
||
|
*/
|
||
|
public static void notNull(String message, Object... objects) {
|
||
|
for (Object obj : objects) {
|
||
|
if (obj == null) {
|
||
|
throw new OrganizationRunTimeException(message);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 判断入参为null
|
||
|
*
|
||
|
* @param object 待检查参数
|
||
|
* @param message 检查失败返回的异常信息
|
||
|
*/
|
||
|
public static void isNull(Object object, String message) {
|
||
|
if (object != null) {
|
||
|
throw new OrganizationRunTimeException(message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 判断集合是否为空
|
||
|
*
|
||
|
* @param collection 待检查参数
|
||
|
* @param message 检查失败返回的异常信息
|
||
|
*/
|
||
|
public static void isEmpty(Collection<?> collection, String message) {
|
||
|
if (!CollectionUtils.isEmpty(collection)) {
|
||
|
throw new OrganizationRunTimeException(message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 判断集合不为空
|
||
|
*
|
||
|
* @param collection 待检查参数
|
||
|
* @param message 检查失败返回的异常信息
|
||
|
*/
|
||
|
public static void notEmpty(Collection<?> collection, String message) {
|
||
|
if (CollectionUtils.isEmpty(collection)) {
|
||
|
throw new OrganizationRunTimeException(message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 判断数组是否为空
|
||
|
*
|
||
|
* @param arr 待检查参数
|
||
|
* @param message 检查失败返回的异常信息
|
||
|
*/
|
||
|
public static void notEmpty(Object[] arr, String message) {
|
||
|
if (ObjectUtils.isEmpty(arr)) {
|
||
|
throw new OrganizationRunTimeException(message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 判断map是否为空
|
||
|
*
|
||
|
* @param map 待检查参数
|
||
|
* @param message 检查失败返回的异常信息
|
||
|
*/
|
||
|
public static void notEmpty(Map<?, ?> map, String message) {
|
||
|
if (CollectionUtils.isEmpty(map)) {
|
||
|
throw new OrganizationRunTimeException(message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 判断数组元素是否为空
|
||
|
*
|
||
|
* @param arr 待检查参数
|
||
|
* @param message 检查失败返回的异常信息
|
||
|
*/
|
||
|
public static void notNullElement(Object[] arr, String message) {
|
||
|
if (arr != null) {
|
||
|
for (Object obj : arr) {
|
||
|
if (obj == null) {
|
||
|
throw new OrganizationRunTimeException(message);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 判断boolean
|
||
|
*
|
||
|
* @param expression 待检查参数
|
||
|
* @param message 检查失败返回的异常信息
|
||
|
*/
|
||
|
public static void isTrue(boolean expression, String message) {
|
||
|
if (!expression) {
|
||
|
throw new OrganizationRunTimeException(message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void isFalse(boolean expression, String message) {
|
||
|
if (expression) {
|
||
|
throw new OrganizationRunTimeException(message);
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void isBlank(CharSequence cs, String message) {
|
||
|
int strLen;
|
||
|
if (cs != null && (strLen = cs.length()) != 0) {
|
||
|
for (int i = 0; i < strLen; ++i) {
|
||
|
if (!Character.isWhitespace(cs.charAt(i))) {
|
||
|
throw new OrganizationRunTimeException(message);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
|
||
|
public static void notBlank(CharSequence cs, String message) {
|
||
|
int strLen;
|
||
|
if (cs != null && (strLen = cs.length()) != 0) {
|
||
|
for (int i = 0; i < strLen; ++i) {
|
||
|
if (Character.isWhitespace(cs.charAt(i))) {
|
||
|
throw new OrganizationRunTimeException(message);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
if (cs == null || cs.length() == 0) {
|
||
|
throw new OrganizationRunTimeException(message);
|
||
|
}
|
||
|
|
||
|
}
|
||
|
}
|