添加注释,添加重载方法。

dev
ZhouXY108 2024-10-18 18:31:20 +08:00
parent 949c59fc1e
commit 4ea3a3a6ab
1 changed files with 28 additions and 7 deletions

View File

@ -24,21 +24,34 @@ import javax.annotation.Nonnull;
*
*
* <p>
* 使
* {@code false}
* 使
* </p>
*
* <pre>
* 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."));
* </pre>
*
* @author ZhouXY
*/
public class AssertTools {
public static <T> void checkArgumentNotNull(T obj) {
checkCondition(obj != null, () -> new IllegalArgumentException("The argument cannot be null."));
public static <T> void checkArgumentNotNull(T argument) {
checkCondition(argument != null, () -> new IllegalArgumentException("The argument cannot be null."));
}
public static <T> void checkArgumentNotNull(T obj, String errMsg) {
checkCondition(obj != null, () -> new IllegalArgumentException(errMsg));
public static <T> void checkArgumentNotNull(T argument, String errMsg) {
checkCondition(argument != null, () -> new IllegalArgumentException(errMsg));
}
public static <T> void checkArgumentNotNull(T obj, String format, Object... args) {
checkCondition(obj != null, () -> new IllegalArgumentException(String.format(format, args)));
public static <T> void checkArgumentNotNull(T argument, Supplier<String> messageSupplier) {
checkCondition(argument != null, () -> new IllegalArgumentException(messageSupplier.get()));
}
public static <T> 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<String> 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<String> 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)));
}