add methods

This commit is contained in:
Looly 2024-03-21 18:51:23 +08:00
parent e7ace4ae57
commit af85d8beaf
2 changed files with 28 additions and 2 deletions

View File

@ -24,6 +24,19 @@ import java.util.function.Predicate;
*/
public class PredicateUtil {
/**
* 强制转换 {@code Predicate<? super T>} {@code Predicate<T>}.
*
* @param <T> 参数类型
* @param predicate {@link Predicate}
* @return 强转后的{@link Predicate}
* @since 6.0.0
*/
@SuppressWarnings("unchecked")
static <T> Predicate<T> coerce(final Predicate<? super T> predicate) {
return (Predicate<T>) predicate;
}
/**
* 反向条件
*

View File

@ -329,6 +329,19 @@ public class ObjUtil {
return defaultSupplier.get();
}
/**
* 如果指定的对象不为 {@code null},则应用提供的映射函数并返回结果,否则返回 {@code null}
*
* @param source 要检查的对象
* @param handler 要应用的映射函数
* @param <T> 输入对象的类型
* @param <R> 映射函数的返回类型
* @return 映射函数的结果, 如果输入对象为 null,则返回 null
*/
public static <T, R> R apply(final T source, final Function<T, R> handler) {
return defaultIfNull(source, handler, null);
}
/**
* 如果给定对象不为{@code null} 返回自定义handler处理后的结果否则返回默认值
*