package com.zhqc.cloud.common.utils;
import com.zhqc.cloud.common.enums.IOWTBResponseEnum;
import com.zhqc.framerwork.common.Enum.ResponseEnum;
import com.zhqc.framerwork.common.exception.ZhqcValidateException;
import org.apache.commons.lang3.StringUtils;
import org.springframework.util.CollectionUtils;
import javax.swing.text.html.Option;
import java.io.Serializable;
import java.util.*;
/**
* 异常工具类
*
* @author zdd 2020/08/04
*/
public class ExceptionUtils {
public static void isNotNull(Object obj, String msg) {
if (obj instanceof String) {
if (StringUtils.isBlank((String) obj)) {
throw new ZhqcValidateException(IOWTBResponseEnum.CUSTOMIZE_MSG, msg);
}
} else {
if (obj == null) {
throw new ZhqcValidateException(IOWTBResponseEnum.CUSTOMIZE_MSG, msg);
}
}
}
public static void isNull(Object obj, String msg) {
if (obj instanceof String) {
if (StringUtils.isNotBlank((String) obj)) {
throw new ZhqcValidateException(IOWTBResponseEnum.CUSTOMIZE_MSG, msg);
}
} else {
if (obj != null) {
throw new ZhqcValidateException(IOWTBResponseEnum.CUSTOMIZE_MSG, msg);
}
}
}
public static void isTrue(Boolean expression, String msg) {
if (!expression) {
throw new ZhqcValidateException(IOWTBResponseEnum.CUSTOMIZE_MSG, msg);
}
}
public static void isFalse(Boolean expression, String msg) {
if (expression) {
throw new ZhqcValidateException(IOWTBResponseEnum.CUSTOMIZE_MSG, msg);
}
}
public static void isEmpty(Collection<?> collection, String msg) {
if (!CollectionUtils.isEmpty(collection)) {
throw new ZhqcValidateException(IOWTBResponseEnum.CUSTOMIZE_MSG, msg);
}
}
public static void isNotEmpty(Collection<?> collection, String msg) {
if (CollectionUtils.isEmpty(collection)) {
throw new ZhqcValidateException(IOWTBResponseEnum.CUSTOMIZE_MSG, msg);
}
}
public static void collectionIsNotNull(List<Object> list, String msg) {
isFalse(list == null || list.stream().anyMatch(Objects::isNull), msg);
}
}
异常逻辑处理工具类
最新推荐文章于 2024-08-23 15:54:50 发布