添加 Predicates 工具类。

feature/net-util
ZhouXY108 2023-04-23 22:45:59 +08:00
parent ffe077bf5e
commit a771b207f8
3 changed files with 39 additions and 0 deletions

View File

@ -28,6 +28,13 @@
<version>${jackson.version}</version> <version>${jackson.version}</version>
</dependency> </dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
<version>3.12.0</version>
<scope>test</scope>
</dependency>
<dependency> <dependency>
<groupId>ch.qos.logback</groupId> <groupId>ch.qos.logback</groupId>
<artifactId>logback-classic</artifactId> <artifactId>logback-classic</artifactId>

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;
}
}