mirror of
https://gitee.com/mybatis-flex/mybatis-flex.git
synced 2025-12-07 00:58:24 +08:00
feat: 添加更多 Flex 断言。
This commit is contained in:
parent
927f60e99b
commit
940c7018d1
@ -16,6 +16,7 @@
|
||||
|
||||
package com.mybatisflex.core.exception;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
@ -33,12 +34,12 @@ public final class FlexAssert {
|
||||
* 断言对象不为空,如果为空抛出异常,并指明哪个对象为空。
|
||||
*
|
||||
* @param obj 对象
|
||||
* @param msg 错误消息
|
||||
* @param message 错误消息
|
||||
* @throws MybatisFlexException 如果对象为空,抛出此异常。
|
||||
*/
|
||||
public static void notNull(Object obj, String msg) {
|
||||
public static void notNull(Object obj, String message) {
|
||||
if (obj == null) {
|
||||
throw FlexExceptions.wrap(msg);
|
||||
throw FlexExceptions.wrap(message);
|
||||
}
|
||||
}
|
||||
|
||||
@ -46,12 +47,38 @@ public final class FlexAssert {
|
||||
* 断言 Map 集合不为 {@code null} 或者空集合,如果为空则抛出异常,并指明为什么不允许为空集合。
|
||||
*
|
||||
* @param map Map 集合
|
||||
* @param msg 错误消息
|
||||
* @param message 错误消息
|
||||
* @throws MybatisFlexException 如果集合为空,抛出此异常。
|
||||
*/
|
||||
public static void notEmpty(Map<?, ?> map, String msg) {
|
||||
public static void notEmpty(Map<?, ?> map, String message) {
|
||||
if (map == null || map.isEmpty()) {
|
||||
throw FlexExceptions.wrap(msg);
|
||||
throw FlexExceptions.wrap(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言集合不为 {@code null} 或者空集合,如果为空则抛出异常,并指明为什么不允许为空集合。
|
||||
*
|
||||
* @param collection 集合
|
||||
* @param message 错误消息
|
||||
* @throws MybatisFlexException 如果集合为空,抛出此异常。
|
||||
*/
|
||||
public static void notEmpty(Collection<?> collection, String message) {
|
||||
if (collection == null || collection.isEmpty()) {
|
||||
throw FlexExceptions.wrap(message);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 断言数组不为 {@code null} 或者空数组,如果为空则抛出异常,并指明为什么不允许为空数组。
|
||||
*
|
||||
* @param array 数组
|
||||
* @param message 错误消息
|
||||
* @throws MybatisFlexException 如果数组为空,抛出此异常。
|
||||
*/
|
||||
public static <T> void notEmpty(T[] array, String message) {
|
||||
if (array == null || array.length == 0) {
|
||||
throw FlexExceptions.wrap(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user