com.google.common.base
Class Predicates

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

public final class Predicates
extends Object

Predicates 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>
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
<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>
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.
 
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.


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.


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.


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.