修改类名,与 guava 的 Predicates 区分。

This commit is contained in:
zhouxy108 2024-03-14 23:18:44 +08:00
parent dc9e0d1b53
commit 7f80a411db
2 changed files with 5 additions and 5 deletions

View File

@ -29,7 +29,7 @@ import java.util.function.Predicate;
* @since 0.1.0 * @since 0.1.0
* @see Predicate * @see Predicate
*/ */
public class Predicates { public class PredicateTools {
/** /**
* lambda 表达式或者方法引用指明为对应类型的 {@link Predicate} 对象 * lambda 表达式或者方法引用指明为对应类型的 {@link Predicate} 对象
@ -38,7 +38,7 @@ public class Predicates {
* 等方法连接其它 {@code Predicate<? super T>} 对象 * 等方法连接其它 {@code Predicate<? super T>} 对象
* *
* <pre> * <pre>
* Predicate&lt;String&gt; predicate = Predicates.&lt;String&gt;of(Objects::nonNull) * Predicate&lt;String&gt; predicate = PredicateTools.&lt;String&gt;from(Objects::nonNull)
* .and(StringUtils::isNotEmpty); * .and(StringUtils::isNotEmpty);
* </pre> * </pre>
* *
@ -46,11 +46,11 @@ public class Predicates {
* @param predicate Lambda 表达式 * @param predicate Lambda 表达式
* @return 传入的表达式自动成为 {@link Predicate} 实例 * @return 传入的表达式自动成为 {@link Predicate} 实例
*/ */
public static <T> Predicate<T> of(Predicate<T> predicate) { public static <T> Predicate<T> from(Predicate<T> predicate) {
return predicate; return predicate;
} }
private Predicates() { private PredicateTools() {
throw new IllegalStateException("Utility class"); throw new IllegalStateException("Utility class");
} }
} }

View File

@ -13,7 +13,7 @@ class FunctionTests {
@Test @Test
void test() { void test() {
String str = ""; String str = "";
Predicate<String> predicate = Predicates.<String>of(Objects::nonNull) Predicate<String> predicate = PredicateTools.<String>from(Objects::nonNull)
.and(StringUtils::isNotBlank); .and(StringUtils::isNotBlank);
assertFalse(predicate.test(str), "校验应是不通过"); assertFalse(predicate.test(str), "校验应是不通过");
} }