Package com.strobel.core
Class Predicates
- java.lang.Object
-
- com.strobel.core.Predicates
-
public final class Predicates extends java.lang.ObjectStatic utility methods pertaining toPredicateinstances.All of the returned predicates are serializable if given serializable parameters.
-
-
Field Summary
Fields Modifier and Type Field Description static Predicate<java.lang.Object>FALSEa predicate who's result is alwaysfalse.static Predicate<java.lang.Object>IS_NULLa predicate that evaluates totrueif the reference being tested isnull.static Predicate<java.lang.Object>NON_NULLa predicate that evaluates totrueif the reference being tested is notnull.static Predicate<java.lang.Object>TRUEa predicate who's result is alwaystrue.
-
Constructor Summary
Constructors Modifier Constructor Description privatePredicates()singleton utils
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <T> Predicate<T>alwaysFalse()Returns a predicate who's result is alwaysfalse.static <T> Predicate<T>alwaysTrue()Returns a predicate who's result is alwaystrue.static <T> Predicate<T>and(Predicate<? super T>... components)Returns a predicate that evaluates totrueif all of the component predicates evaluate totrue.(package private) static <T> Predicate<T>and(Predicate<? super T> first, Predicate<? super T>... components)Returns a predicate that evaluates totrueif all of the component predicates evaluate totrue.(package private) static <T> Predicate<T>and(Predicate<? super T> first, java.lang.Iterable<Predicate<? super T>> components)Returns a predicate that evaluates totrueif all of the component predicates evaluate totrue.static <T> Predicate<T>and(Predicate<T> first, Predicate<? super T> second)Returns a predicate that evaluates totrueif all of the component predicates evaluate totrue.static <T> Predicate<T>and(java.lang.Iterable<Predicate<? super T>> components)Returns a predicate that evaluates totrueif all of the component predicates evaluate totrue.static <T> Predicate<T>contains(java.util.Collection<? extends T> target)Creates a predicate that evaluates totrueif the tested object is a member of the provided collection.static <T> Predicate<T>containsKey(java.util.Map<? extends T,?> target)Creates a predicate that evaluates totrueif the tested object is a key in the provided map.static <T> Predicate<T>instanceOf(java.lang.Class<?> clazz)Returns a predicate that evaluates totrueif 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 totrueif 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>negate(Predicate<? super T> predicate)Returns a predicate that evaluates totrueif the provided predicate evaluates tofalsestatic <T> Predicate<T>nonNull()Returns a predicate that evaluates totrueif the reference being tested is non-null.static <T> Predicate<T>or(Predicate<? super T>... components)Returns a predicate that evaluates totrueif any of the component predicates evaluate totrue.(package private) static <T> Predicate<T>or(Predicate<? super T> first, java.lang.Iterable<Predicate<? super T>> components)Returns a predicate that evaluates totrueif any of the component predicates evaluate totrue.static <T> Predicate<T>or(Predicate<T> first, Predicate<? super T> second)Returns a predicate that evaluates totrueif any of the component predicates evaluate totrue.(package private) static <T> Predicate<T>or(Predicate<T> first, Predicate<? super T>... components)Returns a predicate that evaluates totrueif any of the component predicates evaluate totrue.static <T> Predicate<T>or(java.lang.Iterable<Predicate<? super T>> components)Returns a predicate that evaluates totrueif any of the component predicates evaluate totrue.private static <T> java.util.List<T>safeCopyOf(java.lang.Iterable<T> iterable)private static <T> T[]safeCopyOf(T... array)private static <T> java.util.List<T>safeCopyOf(T first, java.lang.Iterable<T> iterable)private static <T> T[]safeCopyOf(T first, T... array)static <T> Predicate<T>xor(Predicate<T> first, Predicate<? super T> second)Returns a predicate that evaluates totrueif all or none of the component predicates evaluate totrue.
-
-
-
Field Detail
-
IS_NULL
public static final Predicate<java.lang.Object> IS_NULL
a predicate that evaluates totrueif the reference being tested isnull.
-
NON_NULL
public static final Predicate<java.lang.Object> NON_NULL
a predicate that evaluates totrueif the reference being tested is notnull.
-
FALSE
public static final Predicate<java.lang.Object> FALSE
a predicate who's result is alwaysfalse.
-
TRUE
public static final Predicate<java.lang.Object> TRUE
a predicate who's result is alwaystrue.
-
-
Method Detail
-
isNull
public static <T> Predicate<T> isNull()
Returns a predicate that evaluates totrueif the reference being tested isnull.- Returns:
- a predicate that evaluates to
trueif the reference being tested isnull
-
nonNull
public static <T> Predicate<T> nonNull()
Returns a predicate that evaluates totrueif the reference being tested is non-null.- Returns:
- a predicate that evaluates to
trueif the reference being tested is is non-null
-
alwaysFalse
public static <T> Predicate<T> alwaysFalse()
Returns a predicate who's result is alwaysfalse.- Returns:
- a predicate who's result is always
false.
-
alwaysTrue
public static <T> Predicate<T> alwaysTrue()
Returns a predicate who's result is alwaystrue.- Returns:
- a predicate who's result is always
true.
-
instanceOf
public static <T> Predicate<T> instanceOf(java.lang.Class<?> clazz)
Returns a predicate that evaluates totrueif the object being tested is an instance of the provided class. If the object being tested isnullthis predicate evaluates tofalse.- Parameters:
clazz- The target class to be matched by the predicate.- Returns:
- a predicate that evaluates to
trueif the object being tested is an instance of the provided class
-
isSame
public static <T> Predicate<T> isSame(T target)
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
public static <T> Predicate<T> isEqual(T target)
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
public static <T> Predicate<T> contains(java.util.Collection<? extends T> target)
Creates a predicate that evaluates totrueif 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
trueif 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
public static <T> Predicate<T> containsKey(java.util.Map<? extends T,?> target)
Creates a predicate that evaluates totrueif 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
trueif 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
public static <T> Predicate<T> negate(Predicate<? super T> predicate)
Returns a predicate that evaluates totrueif 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
public static <T> Predicate<T> and(Predicate<T> first, Predicate<? super T> second)
Returns a predicate that evaluates totrueif all of the component predicates evaluate totrue. The components are evaluated in order, and evaluation will terminate upon the firstfalsepredicate.- 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
trueiff all component predicates aretrue.
-
and
public static <T> Predicate<T> and(java.lang.Iterable<Predicate<? super T>> components)
Returns a predicate that evaluates totrueif all of the component predicates evaluate totrue. The components are evaluated in order, and evaluation will end upon the firstfalsepredicate.- 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
trueiff all component predicates aretrue.
-
and
static <T> Predicate<T> and(Predicate<? super T> first, java.lang.Iterable<Predicate<? super T>> components)
Returns a predicate that evaluates totrueif all of the component predicates evaluate totrue. The components are evaluated in order, and evaluation will end upon the firstfalsepredicate.- 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
trueiff all component predicates aretrue.
-
and
@SafeVarargs public static <T> Predicate<T> and(Predicate<? super T>... components)
Returns a predicate that evaluates totrueif all of the component predicates evaluate totrue. The components are evaluated in order, and evaluation will end upon the firstfalsepredicate.- 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
trueiff all component predicates aretrue.
-
and
@SafeVarargs static <T> Predicate<T> and(Predicate<? super T> first, Predicate<? super T>... components)
Returns a predicate that evaluates totrueif all of the component predicates evaluate totrue. The components are evaluated in order, and evaluation will end upon the firstfalsepredicate.- 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
trueiff all component predicates aretrue.
-
or
public static <T> Predicate<T> or(Predicate<T> first, Predicate<? super T> second)
Returns a predicate that evaluates totrueif any of the component predicates evaluate totrue. The components are evaluated in order, and evaluation will end upon the firsttruepredicate.- 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
trueif any component predicate's result istrue.
-
or
public static <T> Predicate<T> or(java.lang.Iterable<Predicate<? super T>> components)
Returns a predicate that evaluates totrueif any of the component predicates evaluate totrue. The components are evaluated in order, and evaluation will end upon the firsttruepredicate.- 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
trueif any component predicate's result istrue.
-
or
static <T> Predicate<T> or(Predicate<? super T> first, java.lang.Iterable<Predicate<? super T>> components)
Returns a predicate that evaluates totrueif any of the component predicates evaluate totrue. The components are evaluated in order, and evaluation will end upon the firsttruepredicate.- 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
trueif any component predicate's result istrue.
-
or
@SafeVarargs public static <T> Predicate<T> or(Predicate<? super T>... components)
Returns a predicate that evaluates totrueif any of the component predicates evaluate totrue. The components are evaluated in order, and evaluation will terminate upon the firsttruepredicate.- 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
trueif any component predicate's result istrue.
-
or
@SafeVarargs static <T> Predicate<T> or(Predicate<T> first, Predicate<? super T>... components)
Returns a predicate that evaluates totrueif any of the component predicates evaluate totrue. The components are evaluated in order, and evaluation will terminate upon the firsttruepredicate.- 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
trueif any component predicate's result istrue.
-
xor
public static <T> Predicate<T> xor(Predicate<T> first, Predicate<? super T> second)
Returns a predicate that evaluates totrueif 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
trueif all or none of the component predicates evaluate totrue
-
safeCopyOf
@SafeVarargs private static <T> T[] safeCopyOf(T... array)
-
safeCopyOf
@SafeVarargs private static <T> T[] safeCopyOf(T first, T... array)
-
safeCopyOf
private static <T> java.util.List<T> safeCopyOf(T first, java.lang.Iterable<T> iterable)
-
safeCopyOf
private static <T> java.util.List<T> safeCopyOf(java.lang.Iterable<T> iterable)
-
-