Interface CheckedPredicate<T>
- Type Parameters:
T- input type - 输入类型
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
Checked Predicate - Predicate that can throw checked exceptions
可抛出受检异常的 Predicate - 扩展 JDK Predicate 支持受检异常
Extends JDK Predicate to allow throwing checked exceptions in lambdas.
扩展 JDK Predicate,支持在 lambda 中抛出受检异常。
Features | 主要功能:
- Throw checked exceptions in lambda - 在 lambda 中抛出受检异常
- Convert to standard Predicate (unchecked) - 转换为标准 Predicate
- Silent execution (testQuietly/testOrDefault) - 静默执行
- Logical operations (and/or/negate) - 逻辑操作
Usage Examples | 使用示例:
CheckedPredicate<Path> isLarge = path -> Files.size(path) > 1024;
paths.stream().filter(isLarge.unchecked()).toList();
boolean result = isLarge.testOrDefault(path, false);
Security | 安全性:
- Thread-safe: Yes (stateless) - 线程安全: 是 (无状态)
- Null-safe: No - 空值安全: 否
- Since:
- JDK 25, opencode-base-core V1.0.0
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptiondefault CheckedPredicate<T> and(CheckedPredicate<? super T> other) Logical AND 逻辑与default CheckedPredicate<T> negate()Negates 取反static <T> CheckedPredicate<T> Wraps a standard Predicate as a CheckedPredicate 将普通 Predicate 包装为 CheckedPredicatedefault CheckedPredicate<T> or(CheckedPredicate<? super T> other) Logical OR 逻辑或booleanTests a condition that may throw a checked exception 测试条件,可能抛出受检异常default booleantestOrDefault(T t, boolean defaultValue) Silently tests, returning the specified default on exception 静默测试,异常时返回指定默认值default booleantestQuietly(T t) Silently tests, returning false on exception 静默测试,异常时返回 falseConverts 转换为标准 Predicate,受检异常包装为 RuntimeException
-
Method Details
-
test
-
unchecked
-
testQuietly
Silently tests, returning false on exception 静默测试,异常时返回 false- Parameters:
t- the value | 输入值- Returns:
- the result | 测试结果,异常时返回 false
-
testOrDefault
Silently tests, returning the specified default on exception 静默测试,异常时返回指定默认值- Parameters:
t- the value | 输入值defaultValue- the default value | 默认值- Returns:
- the result | 测试结果或默认值
-
negate
-
and
Logical AND 逻辑与- Parameters:
other- the value | 另一个 Predicate- Returns:
- the result | 组合后的 Predicate
-
or
Logical OR 逻辑或- Parameters:
other- the value | 另一个 Predicate- Returns:
- the result | 组合后的 Predicate
-
of
Wraps a standard Predicate as a CheckedPredicate 将普通 Predicate 包装为 CheckedPredicate- Type Parameters:
T- the value | 输入类型- Parameters:
predicate- the value | 普通 Predicate- Returns:
- CheckedPredicate
-