Interface Predicate<T>

Type Parameters:
T - The type of the predicate input.
Functional Interface:
This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

@ConsumerType @FunctionalInterface public interface Predicate<T>
A predicate that accepts a single argument and produces a boolean result.

This is a functional interface and can be used as the assignment target for a lambda expression or method reference.

"ThreadSafe"
  • Method Summary

    Modifier and Type
    Method
    Description
    default Predicate<T>
    and(Predicate<? super T> and)
    Compose this Predicate logical-AND the specified Predicate.
    static <T> Predicate<T>
    Returns a java.util.function.Predicate which wraps the specified Predicate and throws any thrown exceptions.
    static <T> Predicate<T>
    asJavaPredicateOrElse(Predicate<T> wrapped, boolean orElse)
    Returns a java.util.function.Predicate which wraps the specified Predicate and the specified value.
    static <T> Predicate<T>
    Returns a java.util.function.Predicate which wraps the specified Predicate and the specified java.util.function.BooleanSupplier.
    static <T> Predicate<T>
    asPredicate(Predicate<T> wrapped)
    Returns a Predicate which wraps the specified java.util.function.Predicate.
    default Predicate<T>
    Return a Predicate which is the negation of this Predicate.
    default Predicate<T>
    or(Predicate<? super T> or)
    Compose this Predicate logical-OR the specified Predicate.
    boolean
    test(T t)
    Evaluates this predicate on the specified argument.
  • Method Details

    • test

      boolean test(T t) throws Exception
      Evaluates this predicate on the specified argument.
      Parameters:
      t - The input to this predicate.
      Returns:
      true if the specified argument is accepted by this predicate; false otherwise.
      Throws:
      Exception - An exception thrown by the method.
    • negate

      default Predicate<T> negate()
      Return a Predicate which is the negation of this Predicate.
      Returns:
      A Predicate which is the negation of this Predicate.
    • and

      default Predicate<T> and(Predicate<? super T> and)
      Compose this Predicate logical-AND the specified Predicate.

      Short-circuiting is used, so the specified Predicate is not called if this Predicate returns false.

      Parameters:
      and - The Predicate to be called after this Predicate is called. Must not be null.
      Returns:
      A Predicate composed of this Predicate and the specified Predicate using logical-AND.
    • or

      default Predicate<T> or(Predicate<? super T> or)
      Compose this Predicate logical-OR the specified Predicate.

      Short-circuiting is used, so the specified Predicate is not called if this Predicate returns true.

      Parameters:
      or - The Predicate to be called after this Predicate is called. Must not be null.
      Returns:
      A Predicate composed of this Predicate and the specified Predicate using logical-OR.
    • asJavaPredicate

      static <T> Predicate<T> asJavaPredicate(Predicate<T> wrapped)
      Returns a java.util.function.Predicate which wraps the specified Predicate and throws any thrown exceptions.

      The returned java.util.function.Predicate will throw any exception thrown by the wrapped Predicate.

      Type Parameters:
      T - The type of the predicate input.
      Parameters:
      wrapped - The Predicate to wrap. Must not be null.
      Returns:
      A java.util.function.Predicate which wraps the specified Predicate.
    • asJavaPredicateOrElse

      static <T> Predicate<T> asJavaPredicateOrElse(Predicate<T> wrapped, boolean orElse)
      Returns a java.util.function.Predicate which wraps the specified Predicate and the specified value.

      If the the specified Predicate throws an Exception, the the specified value is returned.

      Type Parameters:
      T - The type of the predicate input.
      Parameters:
      wrapped - The Predicate to wrap. Must not be null.
      orElse - The value to return if the specified Predicate throws an Exception.
      Returns:
      A java.util.function.Predicate which wraps the specified Predicate and the specified value.
    • asJavaPredicateOrElseGet

      static <T> Predicate<T> asJavaPredicateOrElseGet(Predicate<T> wrapped, BooleanSupplier orElseGet)
      Returns a java.util.function.Predicate which wraps the specified Predicate and the specified java.util.function.BooleanSupplier.

      If the the specified Predicate throws an Exception, the value returned by the specified java.util.function.BooleanSupplier is returned.

      Type Parameters:
      T - The type of the predicate input.
      Parameters:
      wrapped - The Predicate to wrap. Must not be null.
      orElseGet - The java.util.function.BooleanSupplier to call for a return value if the specified Predicate throws an Exception.
      Returns:
      A java.util.function.Predicate which wraps the specified Predicate and the specified java.util.function.BooleanSupplier.
    • asPredicate

      static <T> Predicate<T> asPredicate(Predicate<T> wrapped)
      Returns a Predicate which wraps the specified java.util.function.Predicate.
      Type Parameters:
      T - The type of the predicate input.
      Parameters:
      wrapped - The java.util.function.Predicate to wrap. Must not be null.
      Returns:
      A Predicate which wraps the specified java.util.function.Predicate.