Interface PagingPredicate<K,V>

Type Parameters:
K - type of the entry key
V - type of the entry value
All Superinterfaces:
Predicate<K,V>, Serializable

public interface PagingPredicate<K,V> extends Predicate<K,V>
This interface is a special Predicate which helps to get a page-by-page result of a query. It can be constructed with a page-size, an inner predicate for filtering, and a comparator for sorting. This class is not thread-safe and stateless. To be able to reuse for another query, one should call reset().
Here is an example usage:
 Predicate lessEqualThanFour = Predicates.lessEqual("this", 4);

 // We are constructing our paging predicate with a predicate and a page size. In this case query results
 // are fetched in batches of two.
 PagingPredicate predicate = Predicates.pagingPredicate(lessEqualThanFour, 2);

 // we are initializing our map with integers from 0 to 10 as keys and values.
 IMap map = hazelcastInstance.getMap(...);
 for (int i = 0; i < 10; i++) {
 map.put(i, i);
 }

 // invoking the query
 Collection<Integer> values = map.values(predicate);
 System.out.println("values = " + values) // will print 'values = [0, 1]'
 predicate.nextPage(); // we are setting up paging predicate to fetch the next page in the next call.
 values = map.values(predicate);
 System.out.println("values = " + values);// will print 'values = [2, 3]'
 Entry anchor = predicate.getAnchor();
 System.out.println("anchor -> " + anchor); // will print 'anchor -> 1=1',  since the anchor is the last entry of
                                               // the previous page.
 predicate.previousPage(); // we are setting up paging predicate to fetch previous page in the next call
 values = map.values(predicate);
 System.out.println("values = " + values) // will print 'values = [0, 1]'
 
See Also:
  • Method Summary

    Modifier and Type
    Method
    Description
    Retrieve the anchor object which is the last value object on the previous page.
    Returns the comparator used by this predicate (if any).
    int
    Returns the current page value.
    int
    Returns the page size.
    void
    Sets the page value to next page.
    void
    Sets the page value to previous page.
    void
    Resets for reuse.
    void
    setPage(int page)
    Sets the current page value.

    Methods inherited from interface com.hazelcast.query.Predicate

    apply
  • Method Details

    • reset

      void reset()
      Resets for reuse.
    • nextPage

      void nextPage()
      Sets the page value to next page.
    • previousPage

      void previousPage()
      Sets the page value to previous page.
    • getPage

      int getPage()
      Returns the current page value.
      Returns:
      the current page value.
    • setPage

      void setPage(int page)
      Sets the current page value.
      Parameters:
      page - the current page value.
    • getPageSize

      int getPageSize()
      Returns the page size.
      Returns:
      the page size
    • getComparator

      Comparator<Map.Entry<K,V>> getComparator()
      Returns the comparator used by this predicate (if any).
      Returns:
      the comparator or null
    • getAnchor

      Map.Entry<K,V> getAnchor()
      Retrieve the anchor object which is the last value object on the previous page.

      Note: This method will return `null` on the first page of the query result or if the predicate was not applied for the previous page number.

      Returns:
      Map.Entry the anchor object which is the last value object on the previous page