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

    Modifier and Type
    Method
    Description
    Returns a predicate that represents the logical negation of this predicate.
    static <T> CheckedPredicate<T>
    of(@NonNull CheckedPredicate<T> methodReference)
    Creates a CheckedPredicate from the given method reference or lambda.
    boolean
    test(T t)
    Evaluates this predicate on the given argument.
    default Predicate<T>
    Returns an unchecked Predicate that sneakily throws any exception encountered when testing a value.
  • Method Details

    • of

      static <T> CheckedPredicate<T> of(@NonNull CheckedPredicate<T> methodReference)
      Creates a CheckedPredicate from 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 CheckedPredicate wrapping the given method reference
      See Also:
    • test

      boolean test(T t) throws Throwable
      Evaluates this predicate on the given argument.
      Parameters:
      t - the input argument
      Returns:
      true if the argument satisfies the predicate, false otherwise
      Throws:
      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 CheckedPredicate representing the negated condition
    • unchecked

      default Predicate<T> unchecked()
      Returns an unchecked Predicate that sneakily throws any exception encountered when testing a value.
      Returns:
      a Predicate that may throw any Throwable without declaring it