| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778 |
- package com.punchsettle.server.common.utils;
- import java.util.Collection;
- import java.util.Objects;
- import com.punchsettle.server.common.exception.BusinessException;
- /**
- * @author tyuio
- * @version 1.0.0
- * @description 断言工具类
- * @date 2024/11/26 19:43
- */
- public class Assert {
- /**
- * 判断对象是否为空
- * @param object 待判断对象
- * @param errorMsg 异常提示信息
- * @throws IllegalArgumentException
- */
- public static void isNull(Object object, String errorMsg) throws IllegalArgumentException {
- if (Objects.isNull(object)) {
- throw new IllegalArgumentException(errorMsg);
- }
- if (object instanceof String && ((String) object).isBlank()) {
- throw new IllegalArgumentException(errorMsg);
- }
- }
- /**
- * 判断对象是否为空
- * @param object 待判断对象
- * @throws IllegalArgumentException
- */
- public static void isNull(Object object) throws IllegalArgumentException {
- isNull(object, "传入的对象参数不能为空");
- }
- /**
- * 判断对象是否为空
- * @param object 待判断对象
- * @param errorMsg 异常提示信息
- * @throws BusinessException
- */
- public static void isNullInBusiness(Object object, String errorMsg) throws BusinessException {
- if (Objects.isNull(object)) {
- throw new BusinessException(errorMsg);
- }
- if (object instanceof String && ((String) object).isBlank()) {
- throw new BusinessException(errorMsg);
- }
- }
- /**
- * 判断集合是否为空
- * @param collection 待判断对象
- * @param errorMsg 异常提示信息
- * @return
- * @param <T>
- * @throws IllegalArgumentException
- */
- public static <T> void notEmpty(Collection<T> collection, String errorMsg) throws IllegalArgumentException {
- if (collection == null || collection.isEmpty()) {
- throw new IllegalArgumentException(errorMsg);
- }
- }
- /**
- * 判断集合是否为空
- * @param collection 待判断对象
- * @param <T>
- * @throws IllegalArgumentException
- */
- public static <T> void notEmpty(Collection<T> collection) throws IllegalArgumentException {
- notEmpty(collection, "传入的集合参数不能为空");
- }
- }
|