javadoc.com.google.common.base.Predicates.html Maven / Gradle / Ivy
Predicates (Guava: Google Core Libraries for Java 11.0.1 API)
Overview
Package
Class
Use
Tree
Deprecated
Index
Help
PREV CLASS
NEXT CLASS
FRAMES
NO FRAMES
SUMMARY: NESTED | FIELD | CONSTR | METHOD
DETAIL: FIELD | CONSTR | METHOD
com.google.common.base
Class Predicates
java.lang.Object
com.google.common.base.Predicates
@GwtCompatible(emulated=true)
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.
- Since:
- 2.0 (imported from Google Collections Library)
- Author:
- Kevin Bourrillion
Method Summary | ||
---|---|---|
static
|
alwaysFalse()
Returns a predicate that always evaluates to false . |
|
static
|
alwaysTrue()
Returns a predicate that always evaluates to true . |
|
static
|
and(Iterable<? extends Predicate<? super T>> components)
Returns a predicate that evaluates to true if each of its
components evaluates to true . |
|
static
|
and(Predicate<? super T>... components)
Returns a predicate that evaluates to true if each of its
components evaluates to true . |
|
static
|
and(Predicate<? super T> first,
Predicate<? super T> second)
Returns a predicate that evaluates to true if both of its
components evaluate to true . |
|
static Predicate<Class<?>> |
assignableFrom(Class<?> clazz)
Returns a predicate that evaluates to true if the class being
tested is assignable from the given class. |
|
static
|
compose(Predicate<B> predicate,
Function<A,? extends B> function)
Returns the composition of a function and a predicate. |
|
static Predicate<CharSequence> |
contains(Pattern pattern)
Returns a predicate that evaluates to true if the
CharSequence being tested contains any match for the given
regular expression pattern. |
|
static Predicate<CharSequence> |
containsPattern(String pattern)
Returns a predicate that evaluates to true if the
CharSequence being tested contains any match for the given
regular expression pattern. |
|
static
|
equalTo(T target)
Returns a predicate that evaluates to true if the object being
tested equals() the given target or both are null. |
|
static
|
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 Predicate<Object> |
instanceOf(Class<?> clazz)
Returns a predicate that evaluates to true if the object being
tested is an instance of the given class. |
|
static
|
isNull()
Returns a predicate that evaluates to true if the object reference
being tested is null. |
|
static
|
not(Predicate<T> predicate)
Returns a predicate that evaluates to true if the given predicate
evaluates to false . |
|
static
|
notNull()
Returns a predicate that evaluates to true if the object reference
being tested is not null. |
|
static
|
or(Iterable<? extends Predicate<? super T>> components)
Returns a predicate that evaluates to true if any one of its
components evaluates to true . |
|
static
|
or(Predicate<? super T>... components)
Returns a predicate that evaluates to true if any one of its
components evaluates to true . |
|
static
|
or(Predicate<? super T> first,
Predicate<? super T> second)
Returns a predicate that evaluates to true if 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
@GwtCompatible(serializable=true) public static <T> Predicate<T> alwaysTrue()
- Returns a predicate that always evaluates to
true
.
alwaysFalse
@GwtCompatible(serializable=true) public static <T> Predicate<T> alwaysFalse()
- Returns a predicate that always evaluates to
false
.
isNull
@GwtCompatible(serializable=true) public static <T> Predicate<T> isNull()
- Returns a predicate that evaluates to
true
if the object reference being tested is null.
notNull
@GwtCompatible(serializable=true) 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<T> predicate)
- Returns a predicate that evaluates to
true
if the given predicate evaluates tofalse
.
and
public static <T> Predicate<T> and(Iterable<? extends Predicate<? super T>> components)
- Returns a predicate that evaluates to
true
if each of its components evaluates totrue
. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a false predicate is found. It defensively copies the iterable passed in, so future changes to it won't alter the behavior of this predicate. Ifcomponents
is empty, the returned predicate will always evaluate totrue
.
and
public static <T> Predicate<T> and(Predicate<? super T>... components)
- Returns a predicate that evaluates to
true
if each of its components evaluates totrue
. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a false predicate is found. It defensively copies the array passed in, so future changes to it won't alter the behavior of this predicate. Ifcomponents
is empty, the returned predicate will always evaluate totrue
.
and
public static <T> Predicate<T> and(Predicate<? super T> first, Predicate<? super T> second)
- Returns a predicate that evaluates to
true
if both of its components evaluate totrue
. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a false predicate is found.
or
public static <T> Predicate<T> or(Iterable<? extends Predicate<? super T>> components)
- Returns a predicate that evaluates to
true
if any one of its components evaluates totrue
. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a true predicate is found. It defensively copies the iterable passed in, so future changes to it won't alter the behavior of this predicate. Ifcomponents
is empty, the returned predicate will always evaluate tofalse
.
or
public static <T> Predicate<T> or(Predicate<? super T>... components)
- Returns a predicate that evaluates to
true
if any one of its components evaluates totrue
. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a true predicate is found. It defensively copies the array passed in, so future changes to it won't alter the behavior of this predicate. Ifcomponents
is empty, the returned predicate will always evaluate tofalse
.
or
public static <T> Predicate<T> or(Predicate<? super T> first, Predicate<? super T> second)
- Returns a predicate that evaluates to
true
if either of its components evaluates totrue
. The components are evaluated in order, and evaluation will be "short-circuited" as soon as a true predicate is found.
equalTo
public static <T> Predicate<T> equalTo(@Nullable T target)
- Returns a predicate that evaluates to
true
if the object being testedequals()
the given target or both are null.
instanceOf
@GwtIncompatible(value="Class.isInstance") public static Predicate<Object> instanceOf(Class<?> clazz)
- Returns a predicate that evaluates to
true
if the object being tested is an instance of the given class. If the object being tested isnull
this predicate evaluates tofalse
.If you want to filter an
Iterable
to narrow its type, consider usingIterables.filter(Iterable, Class)
in preference.Warning: contrary to the typical assumptions about predicates (as documented at
Predicate.apply(T)
), the returned predicate may not be consistent with equals. For example,instanceOf(ArrayList.class)
will yield different results for the two equal instancesLists.newArrayList(1)
andArrays.asList(1)
.
assignableFrom
@GwtIncompatible(value="Class.isAssignableFrom") @Beta public static Predicate<Class<?>> assignableFrom(Class<?> clazz)
- Returns a predicate that evaluates to
true
if the class being tested is assignable from the given class. The returned predicate does not allow null inputs.- Since:
- 10.0
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 usePredicates.<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 returnspredicate(function(x))
.- Returns:
- the composition of the provided function and predicate
containsPattern
@GwtIncompatible(value="java.util.regex.Pattern") public static Predicate<CharSequence> containsPattern(String pattern)
- Returns a predicate that evaluates to
true
if theCharSequence
being tested contains any match for the given regular expression pattern. The test used is equivalent toPattern.compile(pattern).matcher(arg).find()
- Throws:
PatternSyntaxException
- if the pattern is invalid- Since:
- 3.0
contains
@GwtIncompatible(value="java.util.regex.Pattern") public static Predicate<CharSequence> contains(Pattern pattern)
- Returns a predicate that evaluates to
true
if theCharSequence
being tested contains any match for the given regular expression pattern. The test used is equivalent topattern.matcher(arg).find()
- Since:
- 3.0
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
Copyright © 2010-2012. All Rights Reserved.