From 4a84941bd94e29f7dc00750c4fe25824fd6e0bcd Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Fri, 1 Nov 2024 10:36:07 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=20checkNotNull=20=E6=96=B9?= =?UTF-8?q?=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../plusone/commons/util/AssertTools.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) 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)