com.hazelcast.query

## Class PagingPredicate<K,V>

- java.lang.Object
- - com.hazelcast.query.PagingPredicate<K,V>

- Type Parameters:
    `K` -
    `V` -
  All Implemented Interfaces:
    DataSerializable, IdentifiedDataSerializable, IndexAwarePredicate<K,V>, Predicate<K,V>, Serializable

      public class PagingPredicate<K,V>
      extends Object
      implements IndexAwarePredicate<K,V>, IdentifiedDataSerializable

  This class 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 page size. In this case query results fetched two
       by two.
       PagingPredicate predicate = new 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 values = map.values(predicate);
       System.out.println("values = " + values) // will print 'values = [0, 1]'
       predicate.nextPage(); // we are setting up paging predicate to fetch 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:
    Serialized Form

- - ### Constructor Summary

    Constructors
    Constructor and Description
    `PagingPredicate()` Used for serialization internally
    `PagingPredicate(Comparator<Map.Entry<K,V>> comparator, int pageSize)` Construct with a comparator and pageSize results will not be filtered results will be ordered via comparator throws `IllegalArgumentException` if pageSize is not greater than 0
    `PagingPredicate(int pageSize)` Construct with a pageSize results will not be filtered results will be natural ordered throws `IllegalArgumentException` if pageSize is not greater than 0
    `PagingPredicate(Predicate<K,V> predicate, Comparator<Map.Entry<K,V>> comparator, int pageSize)` Construct with an inner predicate, comparator and pageSize results will be filtered via inner predicate results will be ordered via comparator throws `IllegalArgumentException` if pageSize is not greater than 0 throws `IllegalArgumentException` if inner predicate is also `PagingPredicate`
    `PagingPredicate(Predicate predicate, int pageSize)` Construct with an inner predicate and pageSize results will be filtered via inner predicate results will be natural ordered throws `IllegalArgumentException` if pageSize is not greater than 0 throws `IllegalArgumentException` if inner predicate is also `PagingPredicate`

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method and Description
    --- | ---
    `boolean` | `apply(Map.Entry mapEntry)` Used for delegating filtering to inner predicate.
    `Set<com.hazelcast.query.impl.QueryableEntry<K,V>>` | `filter(com.hazelcast.query.impl.QueryContext queryContext)` Used if inner predicate is instanceof `IndexAwarePredicate` for filtering.
    `Map.Entry<K,V>` | `getAnchor()` Retrieve the anchor object which is the last value object on the previous page.
    `Comparator<Map.Entry<K,V>>` | `getComparator()`
    `int` | `getFactoryId()` Returns DataSerializableFactory factory ID for this class.
    `int` | `getId()` Returns type identifier for this class.
    `IterationType` | `getIterationType()`
    `int` | `getPage()`
    `int` | `getPageSize()`
    `Predicate<K,V>` | `getPredicate()`
    `boolean` | `isIndexed(com.hazelcast.query.impl.QueryContext queryContext)` Used if inner predicate is instanceof `IndexAwarePredicate` for checking if indexed.
    `void` | `nextPage()` sets the page value to next page
    `void` | `previousPage()` sets the page value to previous page
    `void` | `readData(ObjectDataInput in)` Reads fields from the input stream
    `void` | `reset()` resets for reuse
    `void` | `setIterationType(IterationType iterationType)`
    `void` | `setPage(int page)`
    `void` | `writeData(ObjectDataOutput out)` Writes object fields to output stream

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### Constructor Detail

    - #### PagingPredicate

          public PagingPredicate()

      Used for serialization internally

    - #### PagingPredicate

          public PagingPredicate(int pageSize)

      Construct with a pageSize results will not be filtered results will be natural ordered throws `IllegalArgumentException` if pageSize is not greater than 0
      Parameters:
        `pageSize` - page size

    - #### PagingPredicate

          public PagingPredicate(Predicate predicate,
                                 int pageSize)

      Construct with an inner predicate and pageSize results will be filtered via inner predicate results will be natural ordered throws `IllegalArgumentException` if pageSize is not greater than 0 throws `IllegalArgumentException` if inner predicate is also `PagingPredicate`
      Parameters:
        `predicate` - the inner predicate through which results will be filtered
        `pageSize` - the page size

    - #### PagingPredicate

          public PagingPredicate(Comparator<Map.Entry<K,V>> comparator,
                                 int pageSize)

      Construct with a comparator and pageSize results will not be filtered results will be ordered via comparator throws `IllegalArgumentException` if pageSize is not greater than 0
      Parameters:
        `comparator` - the comparator through which results will be ordered
        `pageSize` - the page size

    - #### PagingPredicate

          public PagingPredicate(Predicate<K,V> predicate,
                                 Comparator<Map.Entry<K,V>> comparator,
                                 int pageSize)

      Construct with an inner predicate, comparator and pageSize results will be filtered via inner predicate results will be ordered via comparator throws `IllegalArgumentException` if pageSize is not greater than 0 throws `IllegalArgumentException` if inner predicate is also `PagingPredicate`
      Parameters:
        `predicate` - the inner predicate through which results will be filtered
        `comparator` - the comparator through which results will be ordered
        `pageSize` - the page size

  - ### Method Detail

    - #### filter

          public Set<com.hazelcast.query.impl.QueryableEntry<K,V>> filter(com.hazelcast.query.impl.QueryContext queryContext)

      Used if inner predicate is instanceof `IndexAwarePredicate` for filtering.
      Specified by:
        `filter` in interface `IndexAwarePredicate<K,V>`
      Parameters:
        `queryContext` -
      Returns:

    - #### isIndexed

          public boolean isIndexed(com.hazelcast.query.impl.QueryContext queryContext)

      Used if inner predicate is instanceof `IndexAwarePredicate` for checking if indexed.
      Specified by:
        `isIndexed` in interface `IndexAwarePredicate<K,V>`
      Parameters:
        `queryContext` -
      Returns:

    - #### apply

          public boolean apply(Map.Entry mapEntry)

      Used for delegating filtering to inner predicate.
      Specified by:
        `apply` in interface `Predicate<K,V>`
      Parameters:
        `mapEntry` -
      Returns:

    - #### reset

          public void reset()

      resets for reuse

    - #### nextPage

          public void nextPage()

      sets the page value to next page

    - #### previousPage

          public void previousPage()

      sets the page value to previous page

    - #### getIterationType

          public IterationType getIterationType()

    - #### setIterationType

          public void setIterationType(IterationType iterationType)

    - #### getPage

          public int getPage()

    - #### setPage

          public void setPage(int page)

    - #### getPageSize

          public int getPageSize()

    - #### getPredicate

          public Predicate<K,V> getPredicate()

    - #### getComparator

          public Comparator<Map.Entry<K,V>> getComparator()

    - #### getAnchor

          public 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.
      Returns:
        Map.Entry the anchor object which is the last value object on the previous page

    - #### writeData

          public void writeData(ObjectDataOutput out)
                         throws IOException

      Description copied from interface: `DataSerializable`
      Writes object fields to output stream
      Specified by:
        `writeData` in interface `DataSerializable`
      Parameters:
        `out` - output
      Throws:
        `IOException` - if an I/O error occurs. In particular, an `IOException` may be thrown if the output stream has been closed.

    - #### readData

          public void readData(ObjectDataInput in)
                        throws IOException

      Description copied from interface: `DataSerializable`
      Reads fields from the input stream
      Specified by:
        `readData` in interface `DataSerializable`
      Parameters:
        `in` - input
      Throws:
        `IOException` - if an I/O error occurs. In particular, an `IOException` may be thrown if the input stream has been closed.

    - #### getFactoryId

          public int getFactoryId()

      Description copied from interface: `IdentifiedDataSerializable`
      Returns DataSerializableFactory factory ID for this class.
      Specified by:
        `getFactoryId` in interface `IdentifiedDataSerializable`
      Returns:
        factory ID

    - #### getId

          public int getId()

      Description copied from interface: `IdentifiedDataSerializable`
      Returns type identifier for this class. It should be unique per DataSerializableFactory.
      Specified by:
        `getId` in interface `IdentifiedDataSerializable`
      Returns:
        type ID

Copyright © 2018. All rights reserved.