添加 Predicates 工具类。

This commit is contained in:
2023-04-23 22:45:59 +08:00
parent ffe077bf5e
commit a771b207f8
3 changed files with 39 additions and 0 deletions

View File

@@ -0,0 +1,10 @@
package xyz.zhouxy.plusone.commons.function;
import java.util.function.Predicate;
public class Predicates<T> {
public final Predicate<T> of(Predicate<? super T> predicate) {
return predicate::test;
}
}

View File

@@ -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<String> predicate = new Predicates<String>().of(this::nonNull)
.or(StringUtils::isNotBlank);
Assert.isTrue(predicate.test(str), "未通过");
}
boolean nonNull(Object obj) {
return obj != null;
}
}