diff --git a/src/main/java/xyz/zhouxy/plusone/commons/function/Predicates.java b/src/main/java/xyz/zhouxy/plusone/commons/function/Predicates.java index d0ee32c..b949d18 100644 --- a/src/main/java/xyz/zhouxy/plusone/commons/function/Predicates.java +++ b/src/main/java/xyz/zhouxy/plusone/commons/function/Predicates.java @@ -2,9 +2,13 @@ package xyz.zhouxy.plusone.commons.function; import java.util.function.Predicate; -public class Predicates { +public class Predicates { - public final Predicate of(Predicate predicate) { + public static Predicate of(Predicate predicate) { return predicate::test; } + + private Predicates() { + throw new IllegalStateException("Utility class"); + } } diff --git a/src/test/java/xyz/zhouxy/plusone/commons/function/FunctionTests.java b/src/test/java/xyz/zhouxy/plusone/commons/function/FunctionTests.java index ddf94b1..1ec1353 100644 --- a/src/test/java/xyz/zhouxy/plusone/commons/function/FunctionTests.java +++ b/src/test/java/xyz/zhouxy/plusone/commons/function/FunctionTests.java @@ -1,5 +1,6 @@ package xyz.zhouxy.plusone.commons.function; +import java.util.Objects; import java.util.function.Predicate; import org.apache.commons.lang3.StringUtils; @@ -11,12 +12,8 @@ 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; + Predicate predicate = Predicates.of(Objects::nonNull) + .and(StringUtils::isNotEmpty); + Assert.isFalse(predicate.test(str), "校验应是不通过"); } }