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 6fdc5e4..8212eb7 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/util/AssertTools.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/util/AssertTools.java @@ -94,6 +94,26 @@ public class AssertTools { // #endregion + // #region - checkNotNull + + public static void checkNotNull(T obj) { + checkCondition(obj != null, NullPointerException::new); + } + + public static void checkNotNull(T obj, String errMsg) { + checkCondition(obj != null, () -> new NullPointerException(errMsg)); + } + + public static void checkNotNull(T obj, Supplier messageSupplier) { + checkCondition(obj != null, () -> new NullPointerException(messageSupplier.get())); + } + + public static void checkNotNull(T obj, String format, Object... args) { + checkCondition(obj != null, () -> new NullPointerException(String.format(format, args))); + } + + // #endregion + // #region - checkCondition public static void checkCondition(boolean condition, @Nonnull Supplier e)