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.
weaver-develop/src/com/engine/junchuang/util/OrganizationAssert.java

163 lines
4.5 KiB
Java

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);
}
}
}