Class Assert
java.lang.Object
com.sure.tool.lang.Assert
- Since:
- 0.1.0
- Author:
- suretool
-
Method Summary
Modifier and TypeMethodDescriptionstatic void无条件抛出断言失败异常。static void断言表达式为假。static voidisInstanceOf(Class<?> type, Object obj, String errorMsgTemplate, Object... params) 断言对象是指定类型实例。static <T> T断言对象非null。static void断言对象为null。static voidisTrue(boolean expression) 断言表达式为真。static void断言表达式为真。static voidmatch(String regex, CharSequence content, String errorMsgTemplate, Object... params) 断言字符串匹配正则。static <T extends CharSequence>
T断言字符串非空白。static <T> Collection<T> notEmpty(Collection<T> collection, String errorMsgTemplate, Object... params) 断言集合非空。static <K,V> Map <K, V> 断言 Map 非空。static <T> T[]断言数组非空。static <T extends CharSequence>
T断言字符串非空(null或空串均失败)。static <T> T断言对象非null。
-
Method Details
-
isTrue
-
isTrue
public static void isTrue(boolean expression) 断言表达式为真。- Parameters:
expression- 表达式
-
isFalse
-
isNull
-
isNotNull
-
notNull
-
notEmpty
public static <T extends CharSequence> T notEmpty(T text, String errorMsgTemplate, Object... params) 断言字符串非空(null或空串均失败)。- Type Parameters:
T- 字符串类型- Parameters:
text- 字符串errorMsgTemplate- 错误信息模板params- 占位符参数- Returns:
- 原字符串
-
notBlank
public static <T extends CharSequence> T notBlank(T text, String errorMsgTemplate, Object... params) 断言字符串非空白。- Type Parameters:
T- 字符串类型- Parameters:
text- 字符串errorMsgTemplate- 错误信息模板params- 占位符参数- Returns:
- 原字符串
-
notEmpty
-
notEmpty
public static <T> Collection<T> notEmpty(Collection<T> collection, String errorMsgTemplate, Object... params) 断言集合非空。- Type Parameters:
T- 元素类型- Parameters:
collection- 集合errorMsgTemplate- 错误信息模板params- 占位符参数- Returns:
- 原集合
-
notEmpty
-
isInstanceOf
-
match
public static void match(String regex, CharSequence content, String errorMsgTemplate, Object... params) 断言字符串匹配正则。- Parameters:
regex- 正则表达式content- 字符串errorMsgTemplate- 错误信息模板params- 占位符参数
-
fail
无条件抛出断言失败异常。- Parameters:
errorMsgTemplate- 错误信息模板params- 占位符参数- Throws:
IllegalArgumentException- 始终抛出
-