From a771b207f88d0234279b3a8208105670256b5b34 Mon Sep 17 00:00:00 2001 From: ZhouXY108 Date: Sun, 23 Apr 2023 22:45:59 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=20Predicates=20=E5=B7=A5?= =?UTF-8?q?=E5=85=B7=E7=B1=BB=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 7 ++++++ .../plusone/commons/function/Predicates.java | 10 +++++++++ .../commons/function/FunctionTests.java | 22 +++++++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 src/main/java/xyz/zhouxy/plusone/commons/function/Predicates.java create mode 100644 src/test/java/xyz/zhouxy/plusone/commons/function/FunctionTests.java diff --git a/pom.xml b/pom.xml index 2544b51..bb2b9c9 100644 --- a/pom.xml +++ b/pom.xml @@ -28,6 +28,13 @@ ${jackson.version} + + org.apache.commons + commons-lang3 + 3.12.0 + test + + ch.qos.logback logback-classic diff --git a/src/main/java/xyz/zhouxy/plusone/commons/function/Predicates.java b/src/main/java/xyz/zhouxy/plusone/commons/function/Predicates.java new file mode 100644 index 0000000..d0ee32c --- /dev/null +++ b/src/main/java/xyz/zhouxy/plusone/commons/function/Predicates.java @@ -0,0 +1,10 @@ +package xyz.zhouxy.plusone.commons.function; + +import java.util.function.Predicate; + +public class Predicates { + + public final Predicate of(Predicate predicate) { + return predicate::test; + } +} diff --git a/src/test/java/xyz/zhouxy/plusone/commons/function/FunctionTests.java b/src/test/java/xyz/zhouxy/plusone/commons/function/FunctionTests.java new file mode 100644 index 0000000..ddf94b1 --- /dev/null +++ b/src/test/java/xyz/zhouxy/plusone/commons/function/FunctionTests.java @@ -0,0 +1,22 @@ +package xyz.zhouxy.plusone.commons.function; + +import java.util.function.Predicate; + +import org.apache.commons.lang3.StringUtils; +import org.junit.jupiter.api.Test; +import xyz.zhouxy.plusone.commons.util.Assert; + +class FunctionTests { + + @Test + void test() { + String str = ""; + Predicate predicate = new Predicates().of(this::nonNull) + .or(StringUtils::isNotBlank); + Assert.isTrue(predicate.test(str), "未通过"); + } + + boolean nonNull(Object obj) { + return obj != null; + } +}