添加 Predicates 工具类。
parent
ffe077bf5e
commit
a771b207f8
7
pom.xml
7
pom.xml
|
@ -28,6 +28,13 @@
|
|||
<version>${jackson.version}</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.apache.commons</groupId>
|
||||
<artifactId>commons-lang3</artifactId>
|
||||
<version>3.12.0</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>ch.qos.logback</groupId>
|
||||
<artifactId>logback-classic</artifactId>
|
||||
|
|
|
@ -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;
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue