forked from plusone/plusone-commons
添加 Predicates 工具类。
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
@@ -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;
|
||||
}
|
||||
}
|
Reference in New Issue
Block a user