public class PredicateToolkit
extends java.lang.Object
Predicate
matching various criteria.Modifier and Type | Field and Description |
---|---|
private static java.util.function.Predicate<java.lang.Object> |
FALSE |
private static java.util.function.Predicate<java.lang.Object> |
TRUE |
Constructor and Description |
---|
PredicateToolkit() |
Modifier and Type | Method and Description |
---|---|
static <T> java.util.function.Predicate<T> |
and(java.util.Collection<java.util.function.Predicate<T>> predicates)
Combine a collection of predicates using an AND operation.
|
static <T,M extends java.lang.Comparable<? super M>> |
centerContained(IMemberAccessor<? extends IRange<M>,T> rangeAccessor,
IRange<M> limit)
Return a predicate based on
limit according to
RangeMatchPolicy.CENTER_CONTAINED_IN_RIGHT_OPEN . |
static <T> java.util.function.Predicate<T> |
contains(IMemberAccessor<? extends java.lang.String,T> valueAccessor,
java.lang.String substring)
Create a predicate that checks if a string value contains a specified substring.
|
static <T> java.util.function.Predicate<T> |
equals(IMemberAccessor<?,T> valueAccessor,
java.lang.Object item)
Create a predicate that checks if a value is equal to a specified object.
|
static <T> java.util.function.Predicate<T> |
falsePredicate() |
static java.util.regex.Pattern |
getValidPattern(java.lang.String regexp)
Compile a regular expression into a pattern if possible.
|
static <T> java.util.function.Predicate<T> |
is(T item)
Create a predicate that checks if a value is a specified object.
|
static boolean |
isFalseGuaranteed(java.util.function.Predicate<?> p)
Test if a predicate is guaranteed to always test to
false . |
static boolean |
isTrueGuaranteed(java.util.function.Predicate<?> p)
Test if a predicate is guaranteed to always test to
true . |
static <T,M> java.util.function.Predicate<T> |
less(IMemberAccessor<? extends M,T> valueAccessor,
java.lang.Comparable<? super M> limit)
Create a predicate that compares values to a limit.
|
static <T,M> java.util.function.Predicate<T> |
less(IMemberAccessor<? extends M,T> valueAccessor,
java.lang.Comparable<? super M> limit,
boolean orEqual)
Create a predicate that compares values to a limit.
|
static <T,M> java.util.function.Predicate<T> |
lessOrEqual(IMemberAccessor<? extends M,T> valueAccessor,
java.lang.Comparable<? super M> limit)
Create a predicate that compares values to a limit.
|
static <T> java.util.function.Predicate<T> |
matches(IMemberAccessor<? extends java.lang.String,T> valueAccessor,
java.lang.String regexp)
Create a predicate that checks if a string value matches a regular expression.
|
static <T,M> java.util.function.Predicate<T> |
memberOf(IMemberAccessor<? extends M,T> valueAccessor,
java.util.Set<? extends M> items)
Create a predicate that checks if a value is included in a specified set.
|
static <T,M> java.util.function.Predicate<T> |
more(IMemberAccessor<? extends M,T> valueAccessor,
java.lang.Comparable<? super M> limit)
Create a predicate that compares values to a limit.
|
static <T,M> java.util.function.Predicate<T> |
more(IMemberAccessor<? extends M,T> valueAccessor,
java.lang.Comparable<? super M> limit,
boolean orEqual)
Create a predicate that compares values to a limit.
|
static <T,M> java.util.function.Predicate<T> |
moreOrEqual(IMemberAccessor<? extends M,T> valueAccessor,
java.lang.Comparable<? super M> limit)
Create a predicate that compares values to a limit.
|
static <T> java.util.function.Predicate<T> |
not(java.util.function.Predicate<T> predicate)
Invert a predicate.
|
static <T> java.util.function.Predicate<T> |
notEquals(IMemberAccessor<?,T> valueAccessor,
java.lang.Object item)
Create a predicate that checks if a value is not equal to a specified object.
|
static <T> java.util.function.Predicate<T> |
or(java.util.Collection<java.util.function.Predicate<T>> predicates)
Combine a collection of predicates using an OR operation.
|
static <T,M extends java.lang.Comparable<? super M>> |
rangeContained(IMemberAccessor<? extends IRange<M>,T> rangeAccessor,
IRange<M> limit)
Return a predicate based on
limit according to
RangeMatchPolicy.CONTAINED_IN_CLOSED . |
static <T,M extends java.lang.Comparable<? super M>> |
rangeIntersects(IMemberAccessor<? extends IRange<M>,T> rangeAccessor,
IRange<M> limit)
Return a predicate based on
limit according to
RangeMatchPolicy.CLOSED_INTERSECTS_WITH_CLOSED . |
static <T> java.util.function.Predicate<T> |
truePredicate() |
private static final java.util.function.Predicate<java.lang.Object> FALSE
private static final java.util.function.Predicate<java.lang.Object> TRUE
public static <T> java.util.function.Predicate<T> truePredicate()
true
public static <T> java.util.function.Predicate<T> falsePredicate()
false
public static boolean isTrueGuaranteed(java.util.function.Predicate<?> p)
true
. Note that if this method
returns false
, then it only means that it is unknown what the predicate will return.p
- a predicate to testtrue
if the predicate is guaranteed to test to true
public static boolean isFalseGuaranteed(java.util.function.Predicate<?> p)
false
. Note that if this method
returns false
, then it only means that it is unknown what the predicate will return.p
- a predicate to testtrue
if the predicate is guaranteed to test to false
public static <T> java.util.function.Predicate<T> and(java.util.Collection<java.util.function.Predicate<T>> predicates)
predicates
- input predicatestrue
if all input predicates test to true
public static <T> java.util.function.Predicate<T> or(java.util.Collection<java.util.function.Predicate<T>> predicates)
predicates
- input predicatestrue
if at least one of the input predicates test
to true
public static <T> java.util.function.Predicate<T> not(java.util.function.Predicate<T> predicate)
predicate
- predicate to inverttrue
if the input predicate tests to false
and vice versapublic static <T,M> java.util.function.Predicate<T> less(IMemberAccessor<? extends M,T> valueAccessor, java.lang.Comparable<? super M> limit, boolean orEqual)
The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
T
- type of objects passed into the predicateM
- type of the value that is comparedvalueAccessor
- accessor used to get the value to check from the input typelimit
- value to compare againstorEqual
- if true
, test values that are equal to the limit to true
true
if the value to check is less than, or
optionally equal to, the limit valuepublic static <T,M> java.util.function.Predicate<T> less(IMemberAccessor<? extends M,T> valueAccessor, java.lang.Comparable<? super M> limit)
The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
T
- type of objects passed into the predicateM
- type of the value that is comparedvalueAccessor
- accessor used to get the value to check from the input typelimit
- value to compare againsttrue
if the value to check is strictly less than
the limit valuepublic static <T,M> java.util.function.Predicate<T> lessOrEqual(IMemberAccessor<? extends M,T> valueAccessor, java.lang.Comparable<? super M> limit)
The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
T
- type of objects passed into the predicateM
- type of the value that is comparedvalueAccessor
- accessor used to get the value to check from the input typelimit
- value to compare againsttrue
if the value to check is less than or equal to
the limit valuepublic static <T,M> java.util.function.Predicate<T> more(IMemberAccessor<? extends M,T> valueAccessor, java.lang.Comparable<? super M> limit, boolean orEqual)
The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
T
- type of objects passed into the predicateM
- type of the value that is comparedvalueAccessor
- accessor used to get the value to check from the input typelimit
- value to compare againstorEqual
- if true
, test values that are equal to the limit to true
true
if the value to check is greater than, or
optionally equal to, the limit valuepublic static <T,M> java.util.function.Predicate<T> more(IMemberAccessor<? extends M,T> valueAccessor, java.lang.Comparable<? super M> limit)
The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
T
- type of objects passed into the predicateM
- type of the value that is comparedvalueAccessor
- accessor used to get the value to check from the input typelimit
- value to compare againsttrue
if the value to check is strictly greater than
the limit valuepublic static <T,M> java.util.function.Predicate<T> moreOrEqual(IMemberAccessor<? extends M,T> valueAccessor, java.lang.Comparable<? super M> limit)
The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
T
- type of objects passed into the predicateM
- type of the value that is comparedvalueAccessor
- accessor used to get the value to check from the input typelimit
- value to compare againsttrue
if the value to check is greater than or equal
to the limit valuepublic static <T,M extends java.lang.Comparable<? super M>> java.util.function.Predicate<T> rangeIntersects(IMemberAccessor<? extends IRange<M>,T> rangeAccessor, IRange<M> limit)
limit
according to
RangeMatchPolicy.CLOSED_INTERSECTS_WITH_CLOSED
.
The predicate takes an input object as argument but the range that is checked is extracted from the input object using a member accessor.
T
- type of objects passed into the predicateM
- type of the range value that is comparedrangeAccessor
- accessor used to get the range value to check from the input typelimit
- range value to compare againsttrue
if the range value to check intersects with
the limit rangepublic static <T,M extends java.lang.Comparable<? super M>> java.util.function.Predicate<T> rangeContained(IMemberAccessor<? extends IRange<M>,T> rangeAccessor, IRange<M> limit)
limit
according to
RangeMatchPolicy.CONTAINED_IN_CLOSED
.
The predicate takes an input object as argument but the range that is checked is extracted from the input object using a member accessor.
T
- type of objects passed into the predicateM
- type of the range value that is comparedrangeAccessor
- accessor used to get the range value to check from the input typelimit
- range value to compare againsttrue
if the range value to check is contained in
the limit rangepublic static <T,M extends java.lang.Comparable<? super M>> java.util.function.Predicate<T> centerContained(IMemberAccessor<? extends IRange<M>,T> rangeAccessor, IRange<M> limit)
limit
according to
RangeMatchPolicy.CENTER_CONTAINED_IN_RIGHT_OPEN
.
The predicate takes an input object as argument but the range that is checked is extracted from the input object using a member accessor.
T
- type of objects passed into the predicateM
- type of the range value that is comparedrangeAccessor
- accessor used to get the range value to check from the input typelimit
- range value to compare againsttrue
if the center point of the range value to
check is contained in the limit rangepublic static <T> java.util.function.Predicate<T> equals(IMemberAccessor<?,T> valueAccessor, java.lang.Object item)
The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
T
- type of objects passed into the predicatevalueAccessor
- accessor used to get the value to check from the input typeitem
- object to compare againsttrue
if the value to check is equal to the
specified objectpublic static <T> java.util.function.Predicate<T> notEquals(IMemberAccessor<?,T> valueAccessor, java.lang.Object item)
The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
T
- type of objects passed into the predicatevalueAccessor
- accessor used to get the value to check from the input typeitem
- object to compare againsttrue
if the value to check is not equal to the
specified objectpublic static <T> java.util.function.Predicate<T> is(T item)
The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
T
- type of objects passed into the predicateitem
- object to compare againsttrue
if the value to check is the specified objectpublic static <T,M> java.util.function.Predicate<T> memberOf(IMemberAccessor<? extends M,T> valueAccessor, java.util.Set<? extends M> items)
The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
T
- type of objects passed into the predicateM
- type of the range value that is comparedvalueAccessor
- accessor used to get the value to check from the input typeitems
- set of objects to compare againsttrue
if the object to check is included in the
specified setpublic static <T> java.util.function.Predicate<T> matches(IMemberAccessor<? extends java.lang.String,T> valueAccessor, java.lang.String regexp)
The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
T
- type of objects passed into the predicatevalueAccessor
- string accessor used to get the value to check from the input typeregexp
- the regular expression to matchtrue
if the string value matches the regular
expressionpublic static <T> java.util.function.Predicate<T> contains(IMemberAccessor<? extends java.lang.String,T> valueAccessor, java.lang.String substring)
The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
valueAccessor
- string accessor used to get the value to check from the input typesubstring
- the substring to look fortrue
if the string value contains the substringpublic static java.util.regex.Pattern getValidPattern(java.lang.String regexp)
regexp
- regular expression to compile