Predicate.java官方文档翻译

package java.util.function;

import java.util.Objects;

/**
* Represents a predicate (boolean-valued function) of one argument.
* 表示一个参数的谓词(booean值函数)
*
* <p>这是一个 <a href="package-summary.html">函数式接口</a>
* 它的函数式方法是 {@link #test(Object)}.
*
* @param <T> the type of the input to the predicate
*
* @since 1.8
*/
@FunctionalInterface
public interface Predicate<T> {

/**
* 在给定的参数上计算这个predicate
*
* @param t the input argument
* @return {@code true} if the input argument matches the predicate,
* otherwise {@code false}
*/
boolean test(T t);

/**
* 返回一个predicate,它表示一个predicate与另一个predicate 短路的逻辑与。
*评估组合的predicate时,如果第一个predicate是{@code false},
*那么第二个 {@code other}不会执行。
*
*
* 在评估任一predicate时抛出的任何异常都传递给调用者,如果
* 对该predicate的评估抛出异常,则不会对其他的 {@code other} predicate进行评估。
*
* @param other a predicate that will be logically-ANDed with this
* predicate
* @return a composed predicate that represents the short-circuiting logical
* AND of this predicate and the {@code other} predicate
* @throws NullPointerException if other is null
*/
default Predicate<T> and(Predicate<? super T> other) {
Objects.requireNonNull(other);
return (t) -> test(t) && other.test(t);
}

/**
* 返回一个predicate。表示这个predicate的逻辑非
*
* @return a predicate that represents the logical negation of this
* predicate
*/
default Predicate<T> negate() {
return (t) -> !test(t);
}

/**
* 返回一个predicate,它表示一个predicate与另一个predicate 短路的逻辑或。
*评估组合的predicate时,如果第一个predicate是{@code false},
*那么第二个 {@code other}不会执行。
*
*
* 在评估任一predicate时抛出的任何异常都传递给调用者,如果
* 对该predicate的评估抛出异常,则不会对其他的 {@code other} predicate进行评估。
*
* @param other a predicate that will be logically-ORed with this
* predicate
* @return a composed predicate that represents the short-circuiting logical
* OR of this predicate and the {@code other} predicate
* @throws NullPointerException if other is null
*/
default Predicate<T> or(Predicate<? super T> other) {
Objects.requireNonNull(other);
return (t) -> test(t) || other.test(t);
}

/**
* 返回一个predicate测试两个参数是否相等通过
* {@link Objects#equals(Object, Object)}.
*
* @param <T> the type of arguments to the predicate
* @param targetRef the object reference with which to compare for equality,
* which may be {@code null}
* @return a predicate that tests if two arguments are equal according
* to {@link Objects#equals(Object, Object)}
*/
static <T> Predicate<T> isEqual(Object targetRef) {
return (null == targetRef)
? Objects::isNull
: object -> targetRef.equals(object);
}
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值