Top Description Methods
com.google.common.base

public Interface Predicate<T extends @Nullable Object>

extends Predicate<T extends @Nullable Object>
Known Direct Implementers
com.google.common.base.Predicates.ObjectPredicate, com.google.common.base.Predicates.NotPredicate, com.google.common.base.Predicates.AndPredicate, com.google.common.base.Predicates.OrPredicate, com.google.common.base.Predicates.IsEqualToPredicate, com.google.common.base.Predicates.InstanceOfPredicate, com.google.common.base.Predicates.SubtypeOfPredicate, com.google.common.base.Predicates.InPredicate, com.google.common.base.Predicates.CompositionPredicate, com.google.common.base.Predicates.ContainsPatternPredicate, com.google.common.collect.FilteredEntryMultimap.ValuePredicate, com.google.common.collect.Range, com.google.common.hash.BloomFilter, com.google.common.io.Files.FilePredicate, com.google.common.reflect.TypeToken.TypeFilter, com.google.common.base.CharMatcher, com.google.common.base.Equivalence.EquivalentToPredicate
Annotations
@FunctionalInterface
@GwtCompatible
@ElementTypesAreNonnullByDefault
Imports
com.google.common.annotations.GwtCompatible, javax.annotation.CheckForNull, org.checkerframework.checker.nullness.qual.Nullable

Legacy version of java.util.function.Predicate. Determines a true or false value for a given input.

As this interface extends java.util.function.Predicate, an instance of this type may be used as a Predicate directly. To use a java.util.function.Predicate where a com.google.common.base.Predicate is expected, use the method reference predicate::test.

This interface is now a legacy type. Use java.util.function.Predicate (or the appropriate primitive specialization such as IntPredicate) instead whenever possible. Otherwise, at least reduce explicit dependencies on this type by using lambda expressions or method references instead of classes, leaving your code easier to migrate in the future.

The Predicates class provides common predicates and related utilities.

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

Author
Kevin Bourrillion
Since
2.0

Method Summary

Modifier and TypeMethod and Description
public boolean
apply(T input)

Returns the result of applying this predicate to input (Java 8 users, see notes in the class documentation above).

public boolean
equals(Object object)

Indicates whether another object is equal to this predicate.

public default boolean
test(T
the input argument
input
)

Implements java.util.function.Predicate.test.

Evaluates this predicate on the given argument.
Inherited from java.util.function.Predicate:
andisEqualnegatenotor

Method Detail

applyback to summary
public boolean apply(T input)

Returns the result of applying this predicate to input (Java 8 users, see notes in the class documentation above). This method is generally expected, but not absolutely required, to have the following properties:

  • Its execution does not cause any observable side effects.
  • The computation is consistent with equals; that is, Objects.equal(a, b) implies that predicate.apply(a) == predicate.apply(b)).
Exceptions
NullPointerException:
if input is null and this predicate does not accept null arguments
equalsback to summary
public boolean equals(Object object)

Indicates whether another object is equal to this predicate.

Most implementations will have no reason to override the behavior of Object#equals. However, an implementation may also choose to return true whenever object is a Predicate that it considers interchangeable with this one. "Interchangeable" typically means that this.apply(t) == that.apply(t) for all t of type T). Note that a false result from this method does not imply that the predicates are known not to be interchangeable.

Annotations
@Override
testback to summary
public default boolean test(T input)

Implements java.util.function.Predicate.test.

Doc from java.util.function.Predicate.test.

Evaluates this predicate on the given argument.

Parameters
input:T

the input argument

Returns:boolean

true if the input argument matches the predicate, otherwise false

Annotations
@Override