diff --git a/src/main/java/xyz/zhouxy/plusone/commons/util/AssertTools.java b/src/main/java/xyz/zhouxy/plusone/commons/util/AssertTools.java
index c255d1b..d2446d6 100644
--- a/src/main/java/xyz/zhouxy/plusone/commons/util/AssertTools.java
+++ b/src/main/java/xyz/zhouxy/plusone/commons/util/AssertTools.java
@@ -24,21 +24,34 @@ import javax.annotation.Nonnull;
* 断言工具
*
*
- * 不封装过多判断逻辑,鼓励充分使用项目中的工具类进行逻辑判断。
* 本工具类基本仅对表达式进行判断,并在表达式为 {@code false} 时抛出对应异常。
+ * 不封装过多判断逻辑,鼓励充分使用项目中的工具类进行逻辑判断。
+ *
+ *
+ *
+ * AssertTools.checkArgument(StringUtils.hasText(str), "The argument cannot be blank.");
+ * AssertTools.checkState(ArrayUtils.isNotEmpty(result), "The result cannot be empty.");
+ * AssertTools.checkCondition(!CollectionUtils.isEmpty(roles), () -> new InvalidInputException("The roles cannot be empty."));
+ *
+ *
+ * @author ZhouXY
*/
public class AssertTools {
- public static void checkArgumentNotNull(T obj) {
- checkCondition(obj != null, () -> new IllegalArgumentException("The argument cannot be null."));
+ public static void checkArgumentNotNull(T argument) {
+ checkCondition(argument != null, () -> new IllegalArgumentException("The argument cannot be null."));
}
- public static void checkArgumentNotNull(T obj, String errMsg) {
- checkCondition(obj != null, () -> new IllegalArgumentException(errMsg));
+ public static void checkArgumentNotNull(T argument, String errMsg) {
+ checkCondition(argument != null, () -> new IllegalArgumentException(errMsg));
}
- public static void checkArgumentNotNull(T obj, String format, Object... args) {
- checkCondition(obj != null, () -> new IllegalArgumentException(String.format(format, args)));
+ public static void checkArgumentNotNull(T argument, Supplier messageSupplier) {
+ checkCondition(argument != null, () -> new IllegalArgumentException(messageSupplier.get()));
+ }
+
+ public static void checkArgumentNotNull(T argument, String format, Object... args) {
+ checkCondition(argument != null, () -> new IllegalArgumentException(String.format(format, args)));
}
public static void checkArgument(boolean condition) {
@@ -49,6 +62,10 @@ public class AssertTools {
checkCondition(condition, () -> new IllegalArgumentException(errMsg));
}
+ public static void checkArgument(boolean condition, Supplier messageSupplier) {
+ checkCondition(condition, () -> new IllegalArgumentException(messageSupplier.get()));
+ }
+
public static void checkArgument(boolean condition, String format, Object... args) {
checkCondition(condition, () -> new IllegalArgumentException(String.format(format, args)));
}
@@ -61,6 +78,10 @@ public class AssertTools {
checkCondition(condition, () -> new IllegalStateException(errMsg));
}
+ public static void checkState(boolean condition, Supplier messageSupplier) {
+ checkCondition(condition, () -> new IllegalStateException(messageSupplier.get()));
+ }
+
public static void checkState(boolean condition, String format, Object... args) {
checkCondition(condition, () -> new IllegalStateException(String.format(format, args)));
}