Class Predicates
java.lang.Object
com.loomcache.server.query.Predicates
Factory class providing the full predicate set for distributed map queries.
Each predicate is an immutable record implementing MapPredicate.
Predicates filter map entries by attribute values extracted via AttributeExtractor,
supporting property paths on values and the special "__key" attribute for key access.
Available predicates:
- Comparison: equal, notEqual, greaterThan, greaterThanOrEqual, lessThan, lessThanOrEqual
- Range: between (inclusive)
- Pattern: like/ilike (SQL wildcards: % and _), regex
- Membership: in
- Type: instanceOf
- Fluent DSL: newPredicateBuilder
- Paging: pagingPredicate
- Logical: and, or, not
- Constants: alwaysTrue, alwaysFalse
Example usage:
MapPredicate<String, Employee> filter = Predicates.and(
Predicates.greaterThan("age", 25),
Predicates.like("name", "A%")
);
Thread-safe: all returned predicates are immutable.
-
Method Summary
Modifier and TypeMethodDescriptionstatic <K,V> MapPredicate <K, V> Returns a predicate that always evaluates tofalse.static <K,V> MapPredicate <K, V> Returns a predicate that always evaluates totrue.static <K,V> MapPredicate <K, V> and(MapPredicate<K, V>... predicates) Creates a predicate that is the conjunction (AND) of the given predicates.static <K,V> MapPredicate <K, V> between(String attribute, Comparable<?> from, Comparable<?> to) Creates a predicate that tests:from <= attribute <= to(inclusive).static <K,V> MapPredicate <K, V> Creates a predicate that tests attribute equality:attribute == value.static <K,V> MapPredicate <K, V> greaterEqual(String attribute, Comparable<?> value) Hazelcast-compatible alias forgreaterThanOrEqual(String, Comparable).static <K,V> MapPredicate <K, V> greaterThan(String attribute, Comparable<?> value) Creates a predicate that tests:attribute > value.static <K,V> MapPredicate <K, V> greaterThanOrEqual(String attribute, Comparable<?> value) Creates a predicate that tests:attribute >= value.static <K,V> MapPredicate <K, V> Creates a predicate that tests case-insensitive SQL LIKE pattern matching.static <K,V> MapPredicate <K, V> Creates a predicate that tests:attribute IN (values...).static <K,V> MapPredicate <K, V> instanceOf(Class<?> type) Creates a predicate that tests whether the entry value is an instance of the given type.static <K,V> MapPredicate <K, V> lessEqual(String attribute, Comparable<?> value) Hazelcast-compatible alias forlessThanOrEqual(String, Comparable).static <K,V> MapPredicate <K, V> lessThan(String attribute, Comparable<?> value) Creates a predicate that tests:attribute < value.static <K,V> MapPredicate <K, V> lessThanOrEqual(String attribute, Comparable<?> value) Creates a predicate that tests:attribute <= value.static <K,V> MapPredicate <K, V> Creates a predicate that tests SQL LIKE pattern matching on the attribute's string value.static <K,V> PredicateBuilder <K, V> Creates a fluent predicate builder.static <K,V> MapPredicate <K, V> not(MapPredicate<K, V> predicate) Creates a predicate that negates the given predicate.static <K,V> MapPredicate <K, V> Creates a predicate that tests attribute inequality:attribute != value.static <K,V> MapPredicate <K, V> or(MapPredicate<K, V>... predicates) Creates a predicate that is the disjunction (OR) of the given predicates.static <K,V> PagingPredicate <K, V> pagingPredicate(int pageSize) Creates a stateful paging predicate over all entries.static <K,V> PagingPredicate <K, V> pagingPredicate(MapPredicate<K, V> predicate, int pageSize) Creates a stateful paging predicate over entries matchingpredicate.static <K,V> PagingPredicate <K, V> pagingPredicate(MapPredicate<K, V> predicate, Comparator<? super Map.Entry<K, V>> comparator, int pageSize) Creates a stateful paging predicate with explicit entry ordering.static <K,V> MapPredicate <K, V> partitionPredicate(Object partitionKey, MapPredicate<K, V> predicate) Creates a predicate wrapper that carries an explicit partition key.static <K,V> MapPredicate <K, V> Creates a predicate that tests Java regex matching on the attribute's string value.
-
Method Details
-
newPredicateBuilder
Creates a fluent predicate builder.- Type Parameters:
K- the map key typeV- the map value type- Returns:
- a new predicate builder
-
equal
Creates a predicate that tests attribute equality:attribute == value. Supports numeric coercion (e.g., Integer(1) == Long(1)).- Type Parameters:
K- the map key typeV- the map value type- Parameters:
attribute- the attribute name or path (e.g., "name", "__key", "address.city")value- the value to compare against (may be null)- Returns:
- an equality predicate
-
notEqual
Creates a predicate that tests attribute inequality:attribute != value.- Type Parameters:
K- the map key typeV- the map value type- Parameters:
attribute- the attribute name or pathvalue- the value to compare against (may be null)- Returns:
- an inequality predicate
-
greaterThan
Creates a predicate that tests:attribute > value.- Type Parameters:
K- the map key typeV- the map value type- Parameters:
attribute- the attribute name or pathvalue- the comparable value- Returns:
- a greater-than predicate
-
greaterThanOrEqual
Creates a predicate that tests:attribute >= value.- Type Parameters:
K- the map key typeV- the map value type- Parameters:
attribute- the attribute name or pathvalue- the comparable value- Returns:
- a greater-than-or-equal predicate
-
greaterEqual
Hazelcast-compatible alias forgreaterThanOrEqual(String, Comparable).- Type Parameters:
K- the map key typeV- the map value type- Parameters:
attribute- the attribute name or pathvalue- the comparable value- Returns:
- a greater-than-or-equal predicate
-
lessThan
Creates a predicate that tests:attribute < value.- Type Parameters:
K- the map key typeV- the map value type- Parameters:
attribute- the attribute name or pathvalue- the comparable value- Returns:
- a less-than predicate
-
lessThanOrEqual
Creates a predicate that tests:attribute <= value.- Type Parameters:
K- the map key typeV- the map value type- Parameters:
attribute- the attribute name or pathvalue- the comparable value- Returns:
- a less-than-or-equal predicate
-
lessEqual
Hazelcast-compatible alias forlessThanOrEqual(String, Comparable).- Type Parameters:
K- the map key typeV- the map value type- Parameters:
attribute- the attribute name or pathvalue- the comparable value- Returns:
- a less-than-or-equal predicate
-
between
public static <K,V> MapPredicate<K,V> between(String attribute, Comparable<?> from, Comparable<?> to) Creates a predicate that tests:from <= attribute <= to(inclusive).- Type Parameters:
K- the map key typeV- the map value type- Parameters:
attribute- the attribute name or pathfrom- the lower bound (inclusive)to- the upper bound (inclusive)- Returns:
- a between predicate
-
like
Creates a predicate that tests SQL LIKE pattern matching on the attribute's string value.Wildcards:
%matches any sequence of characters (including empty)_matches exactly one character\%and\_match literal % and _ characters
- Type Parameters:
K- the map key typeV- the map value type- Parameters:
attribute- the attribute name or pathpattern- the SQL LIKE pattern- Returns:
- a like predicate
-
ilike
Creates a predicate that tests case-insensitive SQL LIKE pattern matching.- Type Parameters:
K- the map key typeV- the map value type- Parameters:
attribute- the attribute name or pathpattern- the SQL LIKE pattern- Returns:
- a case-insensitive like predicate
-
regex
Creates a predicate that tests Java regex matching on the attribute's string value.- Type Parameters:
K- the map key typeV- the map value type- Parameters:
attribute- the attribute name or pathpattern- the Java regular expression- Returns:
- a regex predicate
-
partitionPredicate
public static <K,V> MapPredicate<K,V> partitionPredicate(Object partitionKey, MapPredicate<K, V> predicate) Creates a predicate wrapper that carries an explicit partition key.- Type Parameters:
K- the map key typeV- the map value type- Parameters:
partitionKey- the partition key to route withpredicate- the delegate predicate that still filters entries- Returns:
- a partition-key-carrying predicate
-
in
Creates a predicate that tests:attribute IN (values...). Uses numeric coercion for number comparisons.- Type Parameters:
K- the map key typeV- the map value type- Parameters:
attribute- the attribute name or pathvalues- the values to check membership against- Returns:
- an in-set predicate
-
instanceOf
Creates a predicate that tests whether the entry value is an instance of the given type.- Type Parameters:
K- the map key typeV- the map value type- Parameters:
type- the class to check against- Returns:
- an instanceOf predicate
-
pagingPredicate
Creates a stateful paging predicate over all entries.- Type Parameters:
K- the map key typeV- the map value type- Parameters:
pageSize- maximum entries per page- Returns:
- a paging predicate
-
pagingPredicate
Creates a stateful paging predicate over entries matchingpredicate.- Type Parameters:
K- the map key typeV- the map value type- Parameters:
predicate- delegate predicatepageSize- maximum entries per page- Returns:
- a paging predicate
-
pagingPredicate
public static <K,V> PagingPredicate<K,V> pagingPredicate(MapPredicate<K, V> predicate, Comparator<? super Map.Entry<K, V>> comparator, int pageSize) Creates a stateful paging predicate with explicit entry ordering.- Type Parameters:
K- the map key typeV- the map value type- Parameters:
predicate- delegate predicatecomparator- entry comparator used before page slicingpageSize- maximum entries per page- Returns:
- a paging predicate
-
and
Creates a predicate that is the conjunction (AND) of the given predicates. All predicates must match for the result to match. Short-circuits on first failure.- Type Parameters:
K- the map key typeV- the map value type- Parameters:
predicates- the predicates to combine- Returns:
- a conjunction predicate
-
or
Creates a predicate that is the disjunction (OR) of the given predicates. At least one predicate must match for the result to match. Short-circuits on first success.- Type Parameters:
K- the map key typeV- the map value type- Parameters:
predicates- the predicates to combine- Returns:
- a disjunction predicate
-
not
Creates a predicate that negates the given predicate.- Type Parameters:
K- the map key typeV- the map value type- Parameters:
predicate- the predicate to negate- Returns:
- the negated predicate
-
alwaysTrue
Returns a predicate that always evaluates totrue.- Type Parameters:
K- the map key typeV- the map value type- Returns:
- a predicate matching all entries
-
alwaysFalse
Returns a predicate that always evaluates tofalse.- Type Parameters:
K- the map key typeV- the map value type- Returns:
- a predicate matching no entries
-