Class Predicates

java.lang.Object
org.glassfish.jersey.internal.guava.Predicates

public final class Predicates extends Object
Static utility methods pertaining to Predicate instances.

All methods returns serializable predicates as long as they're given serializable parameters.

See the Guava User Guide article on the use of Predicate.

Since:
2.0 (imported from Google Collections Library)
Author:
Kevin Bourrillion
  • Method Summary

    Modifier and Type
    Method
    Description
    static <T> Predicate<T>
    Returns a predicate that always evaluates to true.
    static <A, B> Predicate<A>
    compose(Predicate<B> predicate, Function<A,? extends B> function)
    Returns the composition of a function and a predicate.
    static <T> Predicate<T>
    equalTo(T target)
    Returns a predicate that evaluates to true if the object being tested equals() the given target or both are null.
    static <T> Predicate<T>
    in(Collection<? extends T> target)
    Returns a predicate that evaluates to true if the object reference being tested is a member of the given collection.
    static <T> Predicate<T>
    not(Predicate<T> predicate)
    Returns a predicate that evaluates to true if the given predicate evaluates to false.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Method Details

    • alwaysTrue

      public static <T> Predicate<T> alwaysTrue()
      Returns a predicate that always evaluates to true.
    • not

      public static <T> Predicate<T> not(Predicate<T> predicate)
      Returns a predicate that evaluates to true if the given predicate evaluates to false.
    • equalTo

      public static <T> Predicate<T> equalTo(T target)
      Returns a predicate that evaluates to true if the object being tested equals() the given target or both are null.
    • in

      public static <T> Predicate<T> in(Collection<? extends T> target)
      Returns a predicate that evaluates to true if the object reference being tested is a member of the given collection. It does not defensively copy the collection passed in, so future changes to it will alter the behavior of the predicate.

      This method can technically accept any Collection<?>, but using a typed collection helps prevent bugs. This approach doesn't block any potential users since it is always possible to use Predicates.<Object>in().

      Parameters:
      target - the collection that may contain the function input
    • compose

      public static <A, B> Predicate<A> compose(Predicate<B> predicate, Function<A,? extends B> function)
      Returns the composition of a function and a predicate. For every x, the generated predicate returns predicate(function(x)).
      Returns:
      the composition of the provided function and predicate