新增 checkNotNull 方法

dev
ZhouXY108 2024-11-01 10:36:07 +08:00
parent 87c9273e43
commit 4a84941bd9
1 changed files with 20 additions and 0 deletions

View File

@ -94,6 +94,26 @@ public class AssertTools {
// #endregion
// #region - checkNotNull
public static <T> void checkNotNull(T obj) {
checkCondition(obj != null, NullPointerException::new);
}
public static <T> void checkNotNull(T obj, String errMsg) {
checkCondition(obj != null, () -> new NullPointerException(errMsg));
}
public static <T> void checkNotNull(T obj, Supplier<String> messageSupplier) {
checkCondition(obj != null, () -> new NullPointerException(messageSupplier.get()));
}
public static <T> void checkNotNull(T obj, String format, Object... args) {
checkCondition(obj != null, () -> new NullPointerException(String.format(format, args)));
}
// #endregion
// #region - checkCondition
public static <T extends Exception> void checkCondition(boolean condition, @Nonnull Supplier<T> e)