Class PredicateToolkit
- java.lang.Object
-
- org.openjdk.jmc.common.util.PredicateToolkit
-
-
Constructor Summary
Constructors Constructor Description PredicateToolkit()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description static <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 onlimit
according 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>
falsePredicate()
static Pattern
getValidPattern(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 boolean
isFalseGuaranteed(Predicate<?> p)
Test if a predicate is guaranteed to always test tofalse
.static boolean
isTrueGuaranteed(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>
not(Predicate<T> predicate)
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 onlimit
according 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 onlimit
according toRangeMatchPolicy.CLOSED_INTERSECTS_WITH_CLOSED
.static <T> Predicate<T>
truePredicate()
-
-
-
Method Detail
-
truePredicate
public static <T> Predicate<T> truePredicate()
- Returns:
- a predicate that always will test to
true
-
falsePredicate
public static <T> Predicate<T> falsePredicate()
- Returns:
- a predicate that always will test to
false
-
isTrueGuaranteed
public static boolean isTrueGuaranteed(Predicate<?> p)
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:
true
if the predicate is guaranteed to test totrue
-
isFalseGuaranteed
public static boolean isFalseGuaranteed(Predicate<?> p)
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:
true
if the predicate is guaranteed to test tofalse
-
and
public static <T> Predicate<T> and(Collection<Predicate<T>> predicates)
Combine a collection of predicates using an AND operation.- Parameters:
predicates
- input predicates- Returns:
- a predicate that tests to
true
if all input predicates test totrue
-
or
public static <T> Predicate<T> or(Collection<Predicate<T>> predicates)
Combine a collection of predicates using an OR operation.- Parameters:
predicates
- input predicates- Returns:
- a predicate that tests to
true
if at least one of the input predicates test totrue
-
not
public static <T> Predicate<T> not(Predicate<T> predicate)
Invert a predicate.- Parameters:
predicate
- predicate to invert- Returns:
- a predicate that tests to
true
if the input predicate tests tofalse
and 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
true
if 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
true
if 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
true
if 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
true
if 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
true
if 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
true
if 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 onlimit
according 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
true
if 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 onlimit
according 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
true
if 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 onlimit
according 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
true
if the center point of the range value to check is contained in the limit range
-
equals
public static <T> Predicate<T> equals(IMemberAccessor<?,T> valueAccessor, Object item)
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
true
if the value to check is equal to the specified object
-
notEquals
public 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.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
true
if the value to check is not equal to the specified object
-
is
public static <T> Predicate<T> is(T item)
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
true
if 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
true
if 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
true
if 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
true
if the string value contains the substring
-
getValidPattern
public static Pattern getValidPattern(String regexp)
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
-
-