Class PredicateToolkit
Predicate matching various criteria.-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic <T> Predicate<T>and(Collection<Predicate<T>> predicates) Combine a collection of predicates using an AND operation.static <T,M extends Comparable<? super M>>
Predicate<T>centerContained(IMemberAccessor<? extends IRange<M>, T> rangeAccessor, IRange<M> limit) Return a predicate based onlimitaccording toRangeMatchPolicy.CENTER_CONTAINED_IN_RIGHT_OPEN.static <T> Predicate<T>contains(IMemberAccessor<? extends String, T> valueAccessor, String substring) Create a predicate that checks if a string value contains a specified substring.static <T> Predicate<T>equals(IMemberAccessor<?, T> valueAccessor, Object item) Create a predicate that checks if a value is equal to a specified object.static <T> Predicate<T>static PatterngetValidPattern(String regexp) Compile a regular expression into a pattern if possible.static <T> Predicate<T>is(T item) Create a predicate that checks if a value is a specified object.static booleanisFalseGuaranteed(Predicate<?> p) Test if a predicate is guaranteed to always test tofalse.static booleanisTrueGuaranteed(Predicate<?> p) Test if a predicate is guaranteed to always test totrue.static <T,M> Predicate<T> less(IMemberAccessor<? extends M, T> valueAccessor, Comparable<? super M> limit) Create a predicate that compares values to a limit.static <T,M> Predicate<T> less(IMemberAccessor<? extends M, T> valueAccessor, Comparable<? super M> limit, boolean orEqual) Create a predicate that compares values to a limit.static <T,M> Predicate<T> lessOrEqual(IMemberAccessor<? extends M, T> valueAccessor, Comparable<? super M> limit) Create a predicate that compares values to a limit.static <T> Predicate<T>matches(IMemberAccessor<? extends String, T> valueAccessor, String regexp) Create a predicate that checks if a string value matches a regular expression.static <T,M> Predicate<T> memberOf(IMemberAccessor<? extends M, T> valueAccessor, Set<? extends M> items) Create a predicate that checks if a value is included in a specified set.static <T,M> Predicate<T> more(IMemberAccessor<? extends M, T> valueAccessor, Comparable<? super M> limit) Create a predicate that compares values to a limit.static <T,M> Predicate<T> more(IMemberAccessor<? extends M, T> valueAccessor, Comparable<? super M> limit, boolean orEqual) Create a predicate that compares values to a limit.static <T,M> Predicate<T> moreOrEqual(IMemberAccessor<? extends M, T> valueAccessor, Comparable<? super M> limit) Create a predicate that compares values to a limit.static <T> Predicate<T>Invert a predicate.static <T> Predicate<T>notEquals(IMemberAccessor<?, T> valueAccessor, Object item) Create a predicate that checks if a value is not equal to a specified object.static <T> Predicate<T>or(Collection<Predicate<T>> predicates) Combine a collection of predicates using an OR operation.static <T,M extends Comparable<? super M>>
Predicate<T>rangeContained(IMemberAccessor<? extends IRange<M>, T> rangeAccessor, IRange<M> limit) Return a predicate based onlimitaccording toRangeMatchPolicy.CONTAINED_IN_CLOSED.static <T,M extends Comparable<? super M>>
Predicate<T>rangeIntersects(IMemberAccessor<? extends IRange<M>, T> rangeAccessor, IRange<M> limit) Return a predicate based onlimitaccording toRangeMatchPolicy.CLOSED_INTERSECTS_WITH_CLOSED.static <T> Predicate<T>
-
Constructor Details
-
PredicateToolkit
public PredicateToolkit()
-
-
Method Details
-
truePredicate
- Returns:
- a predicate that always will test to
true
-
falsePredicate
- Returns:
- a predicate that always will test to
false
-
isTrueGuaranteed
Test if a predicate is guaranteed to always test totrue. Note that if this method returnsfalse, then it only means that it is unknown what the predicate will return.- Parameters:
p- a predicate to test- Returns:
trueif the predicate is guaranteed to test totrue
-
isFalseGuaranteed
Test if a predicate is guaranteed to always test tofalse. Note that if this method returnsfalse, then it only means that it is unknown what the predicate will return.- Parameters:
p- a predicate to test- Returns:
trueif the predicate is guaranteed to test tofalse
-
and
Combine a collection of predicates using an AND operation.- Parameters:
predicates- input predicates- Returns:
- a predicate that tests to
trueif all input predicates test totrue
-
or
Combine a collection of predicates using an OR operation.- Parameters:
predicates- input predicates- Returns:
- a predicate that tests to
trueif at least one of the input predicates test totrue
-
not
Invert a predicate.- Parameters:
predicate- predicate to invert- Returns:
- a predicate that tests to
trueif the input predicate tests tofalseand vice versa
-
less
public static <T,M> Predicate<T> less(IMemberAccessor<? extends M, T> valueAccessor, Comparable<? super M> limit, boolean orEqual) Create a predicate that compares values to a 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.
- Type Parameters:
T- type of objects passed into the predicateM- type of the value that is compared- Parameters:
valueAccessor- accessor used to get the value to check from the input typelimit- value to compare againstorEqual- iftrue, test values that are equal to the limit totrue- Returns:
- a predicate that tests to
trueif the value to check is less than, or optionally equal to, the limit value
-
less
public static <T,M> Predicate<T> less(IMemberAccessor<? extends M, T> valueAccessor, Comparable<? super M> limit) Create a predicate that compares values to a 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.
- Type Parameters:
T- type of objects passed into the predicateM- type of the value that is compared- Parameters:
valueAccessor- accessor used to get the value to check from the input typelimit- value to compare against- Returns:
- a predicate that tests to
trueif the value to check is strictly less than the limit value
-
lessOrEqual
public static <T,M> Predicate<T> lessOrEqual(IMemberAccessor<? extends M, T> valueAccessor, Comparable<? super M> limit) Create a predicate that compares values to a 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.
- Type Parameters:
T- type of objects passed into the predicateM- type of the value that is compared- Parameters:
valueAccessor- accessor used to get the value to check from the input typelimit- value to compare against- Returns:
- a predicate that tests to
trueif the value to check is less than or equal to the limit value
-
more
public static <T,M> Predicate<T> more(IMemberAccessor<? extends M, T> valueAccessor, Comparable<? super M> limit, boolean orEqual) Create a predicate that compares values to a 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.
- Type Parameters:
T- type of objects passed into the predicateM- type of the value that is compared- Parameters:
valueAccessor- accessor used to get the value to check from the input typelimit- value to compare againstorEqual- iftrue, test values that are equal to the limit totrue- Returns:
- a predicate that tests to
trueif the value to check is greater than, or optionally equal to, the limit value
-
more
public static <T,M> Predicate<T> more(IMemberAccessor<? extends M, T> valueAccessor, Comparable<? super M> limit) Create a predicate that compares values to a 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.
- Type Parameters:
T- type of objects passed into the predicateM- type of the value that is compared- Parameters:
valueAccessor- accessor used to get the value to check from the input typelimit- value to compare against- Returns:
- a predicate that tests to
trueif the value to check is strictly greater than the limit value
-
moreOrEqual
public static <T,M> Predicate<T> moreOrEqual(IMemberAccessor<? extends M, T> valueAccessor, Comparable<? super M> limit) Create a predicate that compares values to a 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.
- Type Parameters:
T- type of objects passed into the predicateM- type of the value that is compared- Parameters:
valueAccessor- accessor used to get the value to check from the input typelimit- value to compare against- Returns:
- a predicate that tests to
trueif the value to check is greater than or equal to the limit value
-
rangeIntersects
public static <T,M extends Comparable<? super M>> Predicate<T> rangeIntersects(IMemberAccessor<? extends IRange<M>, T> rangeAccessor, IRange<M> limit) Return a predicate based onlimitaccording toRangeMatchPolicy.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.
- Type Parameters:
T- type of objects passed into the predicateM- type of the range value that is compared- Parameters:
rangeAccessor- accessor used to get the range value to check from the input typelimit- range value to compare against- Returns:
- a predicate that tests to
trueif the range value to check intersects with the limit range
-
rangeContained
public static <T,M extends Comparable<? super M>> Predicate<T> rangeContained(IMemberAccessor<? extends IRange<M>, T> rangeAccessor, IRange<M> limit) Return a predicate based onlimitaccording toRangeMatchPolicy.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.
- Type Parameters:
T- type of objects passed into the predicateM- type of the range value that is compared- Parameters:
rangeAccessor- accessor used to get the range value to check from the input typelimit- range value to compare against- Returns:
- a predicate that tests to
trueif the range value to check is contained in the limit range
-
centerContained
public static <T,M extends Comparable<? super M>> Predicate<T> centerContained(IMemberAccessor<? extends IRange<M>, T> rangeAccessor, IRange<M> limit) Return a predicate based onlimitaccording toRangeMatchPolicy.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.
- Type Parameters:
T- type of objects passed into the predicateM- type of the range value that is compared- Parameters:
rangeAccessor- accessor used to get the range value to check from the input typelimit- range value to compare against- Returns:
- a predicate that tests to
trueif the center point of the range value to check is contained in the limit range
-
equals
Create a predicate that checks if a value is equal to a specified object.The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
- Type Parameters:
T- type of objects passed into the predicate- Parameters:
valueAccessor- accessor used to get the value to check from the input typeitem- object to compare against- Returns:
- a predicate that tests to
trueif the value to check is equal to the specified object
-
notEquals
Create a predicate that checks if a value is not equal to a specified object.The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
- Type Parameters:
T- type of objects passed into the predicate- Parameters:
valueAccessor- accessor used to get the value to check from the input typeitem- object to compare against- Returns:
- a predicate that tests to
trueif the value to check is not equal to the specified object
-
is
Create a predicate that checks if a value is a specified object. This check is performed using object identity.The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
- Type Parameters:
T- type of objects passed into the predicate- Parameters:
item- object to compare against- Returns:
- a predicate that tests to
trueif the value to check is the specified object
-
memberOf
public static <T,M> Predicate<T> memberOf(IMemberAccessor<? extends M, T> valueAccessor, Set<? extends M> items) Create a predicate that checks if a value is included in a specified set.The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
- Type Parameters:
T- type of objects passed into the predicateM- type of the range value that is compared- Parameters:
valueAccessor- accessor used to get the value to check from the input typeitems- set of objects to compare against- Returns:
- a predicate that tests to
trueif the object to check is included in the specified set
-
matches
public static <T> Predicate<T> matches(IMemberAccessor<? extends String, T> valueAccessor, String regexp) Create a predicate that checks if a string value matches a regular expression.The predicate takes an input object as argument but the value that is checked is extracted from the input object using a member accessor.
- Type Parameters:
T- type of objects passed into the predicate- Parameters:
valueAccessor- string accessor used to get the value to check from the input typeregexp- the regular expression to match- Returns:
- a predicate that tests to
trueif the string value matches the regular expression
-
contains
public static <T> Predicate<T> contains(IMemberAccessor<? extends String, T> valueAccessor, String substring) Create a predicate that checks if a string value contains a specified 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.
- Parameters:
valueAccessor- string accessor used to get the value to check from the input typesubstring- the substring to look for- Returns:
- a predicate that tests to
trueif the string value contains the substring
-
getValidPattern
Compile a regular expression into a pattern if possible. If the expression can't be compiled, return a valid pattern that will give 0 matches (at least for single lines).- Parameters:
regexp- regular expression to compile- Returns:
- a valid regular expression pattern instance
-