com.google.common.base
Class Predicates

java.lang.Object
  extended by com.google.common.base.Predicates

public final class Predicates
extends Object

Contains static methods for creating the standard set of Predicate objects.

"Lispy, but good."

TODO: considering having these implement a VisitablePredicate interface which specifies an accept(PredicateVisitor) method.

Author:
Kevin Bourrillion

Method Summary
static
<T> Predicate<T>
alwaysFalse()
          Returns a predicate that always evaluates to false.
static
<T> Predicate<T>
alwaysTrue()
          Returns a predicate that always evaluates to true.
static
<T> Predicate<T>
and(Iterable<? extends Predicate<? super T>> components)
          Returns a predicate that evaluates to true iff each of its components evaluates to true.
static
<T> Predicate<T>
and(Predicate<? super T>... components)
          Returns a predicate that evaluates to true iff each of its components evaluates to true.
static
<T> Predicate<T>
and(Predicate<? super T> first, Predicate<? super T> second)
          Returns a predicate that evaluates to true iff both of its components evaluate to true.
static
<A,B> Predicate<A>
compose(Predicate<? super B> predicate, Function<? super A,? extends B> function)
          Returns the composition of a function and a predicate.
static
<T> Predicate<T>
in(Collection<?> 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>
isEqualTo(T target)
          Returns a predicate that evaluates to true iff the object being tested equals() the given target or if both are null.
static
<T> Predicate<T>
isNull()
          Returns a predicate that evaluates to true if the object reference being tested is null.
static Predicate<Object> isSameAs(Object target)
          Returns a predicate that evaluates to true iff the object being tested refers to the same object as the given target.
static
<T> Predicate<T>
not(Predicate<? super T> predicate)
          Returns a predicate that evaluates to true iff the given predicate evaluates to false.
static
<T> Predicate<T>
notNull()
          Returns a predicate that evaluates to true if the object reference being tested is not null.
static
<T> Predicate<T>
or(Iterable<? extends Predicate<? super T>> components)
          Returns a predicate that evaluates to true iff any one of its components evaluates to true.
static
<T> Predicate<T>
or(Predicate<? super T>... components)
          Returns a predicate that evaluates to true iff any one of its components evaluates to true.
static
<T> Predicate<T>
or(Predicate<? super T> first, Predicate<? super T> second)
          Returns a predicate that evaluates to true iff either of its components evaluates to true.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

alwaysTrue

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


alwaysFalse

public static <T> Predicate<T> alwaysFalse()
Returns a predicate that always evaluates to false.


isNull

public static <T> Predicate<T> isNull()
Returns a predicate that evaluates to true if the object reference being tested is null.


notNull

public static <T> Predicate<T> notNull()
Returns a predicate that evaluates to true if the object reference being tested is not null.


not

public static <T> Predicate<T> not(Predicate<? super T> predicate)
Returns a predicate that evaluates to true iff the given predicate evaluates to false.


and

public static <T> Predicate<T> and(Iterable<? extends Predicate<? super T>> components)
Returns a predicate that evaluates to true iff each of its components evaluates to true. The components are evaluated in order, and evaluation will be "short-circuited" as soon as the answer is determined. Does not defensively copy the iterable passed in, so future changes to it will alter the behavior of this predicate. If components is empty, the returned predicate will always evaluate to true.


and

public static <T> Predicate<T> and(Predicate<? super T>... components)
Returns a predicate that evaluates to true iff each of its components evaluates to true. The components are evaluated in order, and evaluation will be "short-circuited" as soon as the answer is determined. Does not defensively copy the array passed in, so future changes to it will alter the behavior of this predicate. If components is empty, the returned predicate will always evaluate to true.


and

public static <T> Predicate<T> and(Predicate<? super T> first,
                                   Predicate<? super T> second)
Returns a predicate that evaluates to true iff both of its components evaluate to true. The components are evaluated in order, and evaluation will be "short-circuited" as soon as the answer is determined.


or

public static <T> Predicate<T> or(Iterable<? extends Predicate<? super T>> components)
Returns a predicate that evaluates to true iff any one of its components evaluates to true. The components are evaluated in order, and evaluation will be "short-circuited" as soon as the answer is determined. Does not defensively copy the iterable passed in, so future changes to it will alter the behavior of this predicate. If components is empty, the returned predicate will always evaluate to false.


or

public static <T> Predicate<T> or(Predicate<? super T>... components)
Returns a predicate that evaluates to true iff any one of its components evaluates to true. The components are evaluated in order, and evaluation will be "short-circuited" as soon as the answer is determined. Does not defensively copy the array passed in, so future changes to it will alter the behavior of this predicate. If components is empty, the returned predicate will always evaluate to false.


or

public static <T> Predicate<T> or(Predicate<? super T> first,
                                  Predicate<? super T> second)
Returns a predicate that evaluates to true iff either of its components evaluates to true. The components are evaluated in order, and evaluation will be "short-circuited" as soon as the answer is determined.


isEqualTo

public static <T> Predicate<T> isEqualTo(@Nullable
                                         T target)
Returns a predicate that evaluates to true iff the object being tested equals() the given target or if both are null. TODO: Change signature to return Predicate<Object>


isSameAs

public static Predicate<Object> isSameAs(@Nullable
                                         Object target)
Returns a predicate that evaluates to true iff the object being tested refers to the same object as the given target.


in

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

Parameters:
target - the collection to test against

compose

public static <A,B> Predicate<A> compose(Predicate<? super B> predicate,
                                         Function<? super 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.
See Also:
Functions.compose(Function, Function)