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 * @throws IllegalArgumentException */ public static void notEmpty(Collection collection, String errorMsg) throws IllegalArgumentException { if (collection == null || collection.isEmpty()) { throw new IllegalArgumentException(errorMsg); } } /** * 判断集合是否为空 * @param collection 待判断对象 * @param * @throws IllegalArgumentException */ public static void notEmpty(Collection collection) throws IllegalArgumentException { notEmpty(collection, "传入的集合参数不能为空"); } }