Class Predicates

java.lang.Object
com.loomcache.server.query.Predicates

public final class Predicates extends Object
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 Details

    • newPredicateBuilder

      public static <K,V> PredicateBuilder<K,V> newPredicateBuilder()
      Creates a fluent predicate builder.
      Type Parameters:
      K - the map key type
      V - the map value type
      Returns:
      a new predicate builder
    • equal

      public static <K,V> MapPredicate<K,V> equal(String attribute, @Nullable Object value)
      Creates a predicate that tests attribute equality: attribute == value. Supports numeric coercion (e.g., Integer(1) == Long(1)).
      Type Parameters:
      K - the map key type
      V - 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

      public static <K,V> MapPredicate<K,V> notEqual(String attribute, @Nullable Object value)
      Creates a predicate that tests attribute inequality: attribute != value.
      Type Parameters:
      K - the map key type
      V - the map value type
      Parameters:
      attribute - the attribute name or path
      value - the value to compare against (may be null)
      Returns:
      an inequality predicate
    • greaterThan

      public static <K,V> MapPredicate<K,V> greaterThan(String attribute, Comparable<?> value)
      Creates a predicate that tests: attribute > value.
      Type Parameters:
      K - the map key type
      V - the map value type
      Parameters:
      attribute - the attribute name or path
      value - the comparable value
      Returns:
      a greater-than predicate
    • greaterThanOrEqual

      public static <K,V> MapPredicate<K,V> greaterThanOrEqual(String attribute, Comparable<?> value)
      Creates a predicate that tests: attribute >= value.
      Type Parameters:
      K - the map key type
      V - the map value type
      Parameters:
      attribute - the attribute name or path
      value - the comparable value
      Returns:
      a greater-than-or-equal predicate
    • greaterEqual

      public static <K,V> MapPredicate<K,V> greaterEqual(String attribute, Comparable<?> value)
      Hazelcast-compatible alias for greaterThanOrEqual(String, Comparable).
      Type Parameters:
      K - the map key type
      V - the map value type
      Parameters:
      attribute - the attribute name or path
      value - the comparable value
      Returns:
      a greater-than-or-equal predicate
    • lessThan

      public static <K,V> MapPredicate<K,V> lessThan(String attribute, Comparable<?> value)
      Creates a predicate that tests: attribute < value.
      Type Parameters:
      K - the map key type
      V - the map value type
      Parameters:
      attribute - the attribute name or path
      value - the comparable value
      Returns:
      a less-than predicate
    • lessThanOrEqual

      public static <K,V> MapPredicate<K,V> lessThanOrEqual(String attribute, Comparable<?> value)
      Creates a predicate that tests: attribute <= value.
      Type Parameters:
      K - the map key type
      V - the map value type
      Parameters:
      attribute - the attribute name or path
      value - the comparable value
      Returns:
      a less-than-or-equal predicate
    • lessEqual

      public static <K,V> MapPredicate<K,V> lessEqual(String attribute, Comparable<?> value)
      Hazelcast-compatible alias for lessThanOrEqual(String, Comparable).
      Type Parameters:
      K - the map key type
      V - the map value type
      Parameters:
      attribute - the attribute name or path
      value - 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 type
      V - the map value type
      Parameters:
      attribute - the attribute name or path
      from - the lower bound (inclusive)
      to - the upper bound (inclusive)
      Returns:
      a between predicate
    • like

      public static <K,V> MapPredicate<K,V> like(String attribute, String pattern)
      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 type
      V - the map value type
      Parameters:
      attribute - the attribute name or path
      pattern - the SQL LIKE pattern
      Returns:
      a like predicate
    • ilike

      public static <K,V> MapPredicate<K,V> ilike(String attribute, String pattern)
      Creates a predicate that tests case-insensitive SQL LIKE pattern matching.
      Type Parameters:
      K - the map key type
      V - the map value type
      Parameters:
      attribute - the attribute name or path
      pattern - the SQL LIKE pattern
      Returns:
      a case-insensitive like predicate
    • regex

      public static <K,V> MapPredicate<K,V> regex(String attribute, String pattern)
      Creates a predicate that tests Java regex matching on the attribute's string value.
      Type Parameters:
      K - the map key type
      V - the map value type
      Parameters:
      attribute - the attribute name or path
      pattern - 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 type
      V - the map value type
      Parameters:
      partitionKey - the partition key to route with
      predicate - the delegate predicate that still filters entries
      Returns:
      a partition-key-carrying predicate
    • in

      public static <K,V> MapPredicate<K,V> in(String attribute, Object... values)
      Creates a predicate that tests: attribute IN (values...). Uses numeric coercion for number comparisons.
      Type Parameters:
      K - the map key type
      V - the map value type
      Parameters:
      attribute - the attribute name or path
      values - the values to check membership against
      Returns:
      an in-set predicate
    • instanceOf

      public 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.
      Type Parameters:
      K - the map key type
      V - the map value type
      Parameters:
      type - the class to check against
      Returns:
      an instanceOf predicate
    • pagingPredicate

      public static <K,V> PagingPredicate<K,V> pagingPredicate(int pageSize)
      Creates a stateful paging predicate over all entries.
      Type Parameters:
      K - the map key type
      V - the map value type
      Parameters:
      pageSize - maximum entries per page
      Returns:
      a paging predicate
    • pagingPredicate

      public static <K,V> PagingPredicate<K,V> pagingPredicate(MapPredicate<K,V> predicate, int pageSize)
      Creates a stateful paging predicate over entries matching predicate.
      Type Parameters:
      K - the map key type
      V - the map value type
      Parameters:
      predicate - delegate predicate
      pageSize - 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 type
      V - the map value type
      Parameters:
      predicate - delegate predicate
      comparator - entry comparator used before page slicing
      pageSize - maximum entries per page
      Returns:
      a paging predicate
    • and

      @SafeVarargs public static <K,V> MapPredicate<K,V> and(MapPredicate<K,V>... predicates)
      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 type
      V - the map value type
      Parameters:
      predicates - the predicates to combine
      Returns:
      a conjunction predicate
    • or

      @SafeVarargs public static <K,V> MapPredicate<K,V> or(MapPredicate<K,V>... predicates)
      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 type
      V - the map value type
      Parameters:
      predicates - the predicates to combine
      Returns:
      a disjunction predicate
    • not

      public static <K,V> MapPredicate<K,V> not(MapPredicate<K,V> predicate)
      Creates a predicate that negates the given predicate.
      Type Parameters:
      K - the map key type
      V - the map value type
      Parameters:
      predicate - the predicate to negate
      Returns:
      the negated predicate
    • alwaysTrue

      public static <K,V> MapPredicate<K,V> alwaysTrue()
      Returns a predicate that always evaluates to true.
      Type Parameters:
      K - the map key type
      V - the map value type
      Returns:
      a predicate matching all entries
    • alwaysFalse

      public static <K,V> MapPredicate<K,V> alwaysFalse()
      Returns a predicate that always evaluates to false.
      Type Parameters:
      K - the map key type
      V - the map value type
      Returns:
      a predicate matching no entries