From 2ca0872f7cb1b0334f04416181203e4c70332107 Mon Sep 17 00:00:00 2001 From: 502647092 Date: Wed, 6 Sep 2017 20:43:17 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E6=B7=BB=E5=8A=A0=E6=96=AD=E8=A8=80?= =?UTF-8?q?=E7=B1=BB=20=E7=AE=80=E5=8C=96=E6=93=8D=E4=BD=9C=E6=B5=81?= =?UTF-8?q?=E7=A8=8B?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Signed-off-by: 502647092 --- pom.xml | 2 +- .../java/pw/yumc/YumCore/utils/Assert.java | 46 +++++++++++++++++++ 2 files changed, 47 insertions(+), 1 deletion(-) create mode 100644 src/main/java/pw/yumc/YumCore/utils/Assert.java diff --git a/pom.xml b/pom.xml index b273a54..ac1e49b 100644 --- a/pom.xml +++ b/pom.xml @@ -4,7 +4,7 @@ 4.0.0 pw.yumc YumCore - 1.8.5 + 1.8.6 ${project.artifactId} diff --git a/src/main/java/pw/yumc/YumCore/utils/Assert.java b/src/main/java/pw/yumc/YumCore/utils/Assert.java new file mode 100644 index 0000000..fe0be7c --- /dev/null +++ b/src/main/java/pw/yumc/YumCore/utils/Assert.java @@ -0,0 +1,46 @@ +package pw.yumc.YumCore.utils; + +import java.util.Objects; +import java.util.function.Consumer; + +/** + * Created with IntelliJ IDEA + * + * @author 喵♂呜 + * Created on 2017/9/1 10:49. + */ +public class Assert { + private T t; + + public static Assert of(T value) { + return new Assert<>(value); + } + + public static void runIsTrue(Boolean bool, Runnable runnable) { + if (bool) + runnable.run(); + } + + public static void runOrElse(Boolean bool, Runnable t, Runnable f) { + if (bool) + t.run(); + else + f.run(); + } + + public Assert(T t) { + this.t = t; + } + + public void runNonNull(Consumer consumer) { + runIsTrue(Objects.nonNull(t), () -> consumer.accept(t)); + } + + public void runIsNull(Consumer consumer) { + runIsTrue(Objects.isNull(t), () -> consumer.accept(t)); + } + + public void runIsAssignable(Class clazz, Consumer consumer) { + runIsTrue(clazz.isAssignableFrom(t.getClass()), () -> consumer.accept(t)); + } +} \ No newline at end of file