Package com.strobel.core
Class Predicates
java.lang.Object
com.strobel.core.Predicates
Static utility methods pertaining to
Predicate
instances.
All of the returned predicates are serializable if given serializable parameters.
-
Field Summary
FieldsModifier and TypeFieldDescriptiona predicate who's result is alwaysfalse
.a predicate that evaluates totrue
if the reference being tested isnull
.a predicate that evaluates totrue
if the reference being tested is notnull
.a predicate who's result is alwaystrue
. -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Predicate
<T> Returns a predicate who's result is alwaysfalse
.static <T> Predicate
<T> Returns a predicate who's result is alwaystrue
.static <T> Predicate
<T> Returns a predicate that evaluates totrue
if all of the component predicates evaluate totrue
.(package private) static <T> Predicate
<T> Returns a predicate that evaluates totrue
if all of the component predicates evaluate totrue
.(package private) static <T> Predicate
<T> Returns a predicate that evaluates totrue
if all of the component predicates evaluate totrue
.static <T> Predicate
<T> Returns a predicate that evaluates totrue
if all of the component predicates evaluate totrue
.static <T> Predicate
<T> Returns a predicate that evaluates totrue
if all of the component predicates evaluate totrue
.static <T> Predicate
<T> contains
(Collection<? extends T> target) Creates a predicate that evaluates totrue
if the tested object is a member of the provided collection.static <T> Predicate
<T> containsKey
(Map<? extends T, ?> target) Creates a predicate that evaluates totrue
if the tested object is a key in the provided map.static <T> Predicate
<T> instanceOf
(Class<?> clazz) Returns a predicate that evaluates totrue
if the object being tested is an instance of the provided class.static <T> Predicate
<T> isEqual
(T target) Returns a predicate who's result matchesObjects.equals(target, t)
.static <T> Predicate
<T> isNull()
Returns a predicate that evaluates totrue
if the reference being tested isnull
.static <T> Predicate
<T> isSame
(T target) Returns a predicate that who's result istarget == object
.static <T> Predicate
<T> Returns a predicate that evaluates totrue
if the provided predicate evaluates tofalse
static <T> Predicate
<T> nonNull()
Returns a predicate that evaluates totrue
if the reference being tested is non-null
.static <T> Predicate
<T> Returns a predicate that evaluates totrue
if any of the component predicates evaluate totrue
.(package private) static <T> Predicate
<T> Returns a predicate that evaluates totrue
if any of the component predicates evaluate totrue
.static <T> Predicate
<T> Returns a predicate that evaluates totrue
if any of the component predicates evaluate totrue
.(package private) static <T> Predicate
<T> Returns a predicate that evaluates totrue
if any of the component predicates evaluate totrue
.static <T> Predicate
<T> Returns a predicate that evaluates totrue
if any of the component predicates evaluate totrue
.private static <T> List
<T> safeCopyOf
(Iterable<T> iterable) private static <T> T[]
safeCopyOf
(T... array) private static <T> List
<T> safeCopyOf
(T first, Iterable<T> iterable) private static <T> T[]
safeCopyOf
(T first, T... array) static <T> Predicate
<T> Returns a predicate that evaluates totrue
if all or none of the component predicates evaluate totrue
.
-
Field Details
-
IS_NULL
a predicate that evaluates totrue
if the reference being tested isnull
. -
NON_NULL
a predicate that evaluates totrue
if the reference being tested is notnull
. -
FALSE
a predicate who's result is alwaysfalse
. -
TRUE
a predicate who's result is alwaystrue
.
-
-
Constructor Details
-
Predicates
private Predicates()singleton utils
-
-
Method Details
-
isNull
Returns a predicate that evaluates totrue
if the reference being tested isnull
.- Returns:
- a predicate that evaluates to
true
if the reference being tested isnull
-
nonNull
Returns a predicate that evaluates totrue
if the reference being tested is non-null
.- Returns:
- a predicate that evaluates to
true
if the reference being tested is is non-null
-
alwaysFalse
Returns a predicate who's result is alwaysfalse
.- Returns:
- a predicate who's result is always
false
.
-
alwaysTrue
Returns a predicate who's result is alwaystrue
.- Returns:
- a predicate who's result is always
true
.
-
instanceOf
Returns a predicate that evaluates totrue
if the object being tested is an instance of the provided class. If the object being tested isnull
this predicate evaluates tofalse
.- Parameters:
clazz
- The target class to be matched by the predicate.- Returns:
- a predicate that evaluates to
true
if the object being tested is an instance of the provided class
-
isSame
Returns a predicate that who's result istarget == object
.- Type Parameters:
T
- the type of predicate values.- Parameters:
target
- The target value to be compared for identity equality.- Returns:
- a predicate that who's result is
target == object
-
isEqual
Returns a predicate who's result matchesObjects.equals(target, t)
.- Type Parameters:
T
- the type of predicate values.- Parameters:
target
- The target value to be compared for equality.- Returns:
- a predicate who's result matches
Objects.equals(target, t)
-
contains
Creates a predicate that evaluates totrue
if the tested object is a member of the provided collection. The collection is not defensively copied, so changes to it will alter the behavior of the predicate.- Type Parameters:
T
- Type of predicate values.- Parameters:
target
- the collection against which objects will be tested.- Returns:
- a predicate that evaluates to
true
if the tested object is a member of the provided collection. The collection is not defensively copied, so changes to it will alter the behavior of the predicate.
-
containsKey
Creates a predicate that evaluates totrue
if the tested object is a key in the provided map. The map is not defensively copied, so changes to it will alter the behavior of the predicate.- Type Parameters:
T
- Type of predicate values.- Parameters:
target
- the map against which objects will be tested.- Returns:
- a predicate that evaluates to
true
if the tested object is a key in the provided map. The map is not defensively copied, so changes to it will alter the behavior of the predicate.
-
negate
Returns a predicate that evaluates totrue
if the provided predicate evaluates tofalse
- Type Parameters:
T
- the type of values evaluated by the predicate.- Parameters:
predicate
- The predicate to be evaluated.- Returns:
- A predicate who's result is the logical inverse of the provided predicate.
-
and
Returns a predicate that evaluates totrue
if all of the component predicates evaluate totrue
. The components are evaluated in order, and evaluation will terminate upon the firstfalse
predicate.- Type Parameters:
T
- the type of values evaluated by the predicates.- Parameters:
first
- initial component predicate to be evaluated.second
- additional component predicate to be evaluated.- Returns:
- A predicate who's result is
true
iff all component predicates aretrue
.
-
and
Returns a predicate that evaluates totrue
if all of the component predicates evaluate totrue
. The components are evaluated in order, and evaluation will end upon the firstfalse
predicate.- Type Parameters:
T
- the type of values evaluated by the predicates.- Parameters:
components
- The predicates to be evaluated.- Returns:
- A predicate who's result is
true
iff all component predicates aretrue
.
-
and
Returns a predicate that evaluates totrue
if all of the component predicates evaluate totrue
. The components are evaluated in order, and evaluation will end upon the firstfalse
predicate.- Type Parameters:
T
- the type of values evaluated by the predicates.- Parameters:
components
- The predicates to be evaluated.- Returns:
- A predicate who's result is
true
iff all component predicates aretrue
.
-
and
Returns a predicate that evaluates totrue
if all of the component predicates evaluate totrue
. The components are evaluated in order, and evaluation will end upon the firstfalse
predicate.- Type Parameters:
T
- the type of values evaluated by the predicates.- Parameters:
components
- The predicates to be evaluated. A copy is made of the components.- Returns:
- A predicate who's result is
true
iff all component predicates aretrue
.
-
and
@SafeVarargs static <T> Predicate<T> and(Predicate<? super T> first, Predicate<? super T>... components) Returns a predicate that evaluates totrue
if all of the component predicates evaluate totrue
. The components are evaluated in order, and evaluation will end upon the firstfalse
predicate.- Type Parameters:
T
- the type of values evaluated by the predicates.- Parameters:
first
- first predicate to be evaluated.components
- The predicates to be evaluated. A copy is made of the components.- Returns:
- A predicate who's result is
true
iff all component predicates aretrue
.
-
or
Returns a predicate that evaluates totrue
if any of the component predicates evaluate totrue
. The components are evaluated in order, and evaluation will end upon the firsttrue
predicate.- Type Parameters:
T
- the type of values evaluated by the predicates.- Parameters:
first
- initial component predicate to be evaluated.second
- additional component predicate to be evaluated.- Returns:
- A predicate who's result is
true
if any component predicate's result istrue
.
-
or
Returns a predicate that evaluates totrue
if any of the component predicates evaluate totrue
. The components are evaluated in order, and evaluation will end upon the firsttrue
predicate.- Type Parameters:
T
- the type of values evaluated by the predicates.- Parameters:
components
- The predicates to be evaluated. A copy is made of the components.- Returns:
- A predicate who's result is
true
if any component predicate's result istrue
.
-
or
Returns a predicate that evaluates totrue
if any of the component predicates evaluate totrue
. The components are evaluated in order, and evaluation will end upon the firsttrue
predicate.- Type Parameters:
T
- the type of values evaluated by the predicates.- Parameters:
components
- The predicates to be evaluated. A copy is made of the components.- Returns:
- A predicate who's result is
true
if any component predicate's result istrue
.
-
or
Returns a predicate that evaluates totrue
if any of the component predicates evaluate totrue
. The components are evaluated in order, and evaluation will terminate upon the firsttrue
predicate.- Type Parameters:
T
- the type of values evaluated by the predicates.- Parameters:
components
- The predicates to be evaluated. A copy is made of the components.- Returns:
- A predicate who's result is
true
if any component predicate's result istrue
.
-
or
Returns a predicate that evaluates totrue
if any of the component predicates evaluate totrue
. The components are evaluated in order, and evaluation will terminate upon the firsttrue
predicate.- Type Parameters:
T
- the type of values evaluated by the predicates.- Parameters:
components
- The predicates to be evaluated. A copy is made of the components.- Returns:
- A predicate who's result is
true
if any component predicate's result istrue
.
-
xor
Returns a predicate that evaluates totrue
if all or none of the component predicates evaluate totrue
. The components are evaluated in order, and evaluation will end if a predicate result fails to match the first predicate's result.- Type Parameters:
T
- the type of values evaluated by the predicates.- Parameters:
first
- initial component predicate to be evaluated.second
- additional component predicate to be evaluated.- Returns:
- a predicate that evaluates to
true
if all or none of the component predicates evaluate totrue
-
safeCopyOf
-
safeCopyOf
-
safeCopyOf
-
safeCopyOf
-