Package io.vavr
Interface CheckedPredicate<T>
-
- Type Parameters:
T- the type of the input to the predicate
- Functional Interface:
- This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.
@FunctionalInterface public interface CheckedPredicate<T>A Predicate that is allowed to throw checked exceptions.
-
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default CheckedPredicate<T>negate()Returns a predicate that represents the logical negation of this predicate.static <T> CheckedPredicate<T>of(@NonNull CheckedPredicate<T> methodReference)Creates aCheckedPredicatefrom the given method reference or lambda.booleantest(T t)Evaluates this predicate on the given argument.default java.util.function.Predicate<T>unchecked()Returns an uncheckedPredicatethat sneakily throws any exception encountered when testing a value.
-
-
-
Method Detail
-
of
static <T> CheckedPredicate<T> of(@NonNull CheckedPredicate<T> methodReference)
Creates aCheckedPredicatefrom the given method reference or lambda.Example usage:
final CheckedPredicate<Boolean> checkedPredicate = CheckedPredicate.of(Boolean::booleanValue); final Predicate<Boolean> predicate = checkedPredicate.unchecked(); // returns true predicate.test(Boolean.TRUE); // may throw an exception predicate.test(null);- Type Parameters:
T- the type of values tested by the predicate- Parameters:
methodReference- typically a method reference, e.g.Type::method- Returns:
- a new
CheckedPredicatewrapping the given method reference - See Also:
CheckedFunction1.of(CheckedFunction1)
-
test
boolean test(T t) throws java.lang.Throwable
Evaluates this predicate on the given argument.- Parameters:
t- the input argument- Returns:
trueif the argument satisfies the predicate,falseotherwise- Throws:
java.lang.Throwable- if an error occurs during evaluation
-
negate
default CheckedPredicate<T> negate()
Returns a predicate that represents the logical negation of this predicate.- Returns:
- a new
CheckedPredicaterepresenting the negated condition
-
unchecked
default java.util.function.Predicate<T> unchecked()
Returns an uncheckedPredicatethat sneakily throws any exception encountered when testing a value.- Returns:
- a
Predicatethat may throw anyThrowablewithout declaring it
-
-