public class PagingPredicate extends Object implements IndexAwarePredicate, IdentifiedDataSerializable
reset()
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]'
| Constructor and Description |
|---|
PagingPredicate()
Used for serialization internally
|
PagingPredicate(Comparator<Map.Entry> 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 predicate,
Comparator<Map.Entry> 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 |
| Modifier and Type | Method and Description |
|---|---|
boolean |
apply(Map.Entry mapEntry)
Used for delegating filtering to inner predicate.
|
Set<QueryableEntry> |
filter(QueryContext queryContext)
Used if inner predicate is instanceof
IndexAwarePredicate for filtering. |
Map.Entry |
getAnchor()
Retrieve the anchor object which is the last value object on the previous page.
|
Comparator<Map.Entry> |
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 |
getPredicate() |
boolean |
isIndexed(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
|
public PagingPredicate()
public PagingPredicate(int pageSize)
IllegalArgumentException if pageSize is not greater than 0pageSize - page sizepublic PagingPredicate(Predicate predicate, int pageSize)
IllegalArgumentException if pageSize is not greater than 0
throws IllegalArgumentException if inner predicate is also PagingPredicatepredicate - the inner predicate through which results will be filteredpageSize - the page sizepublic PagingPredicate(Comparator<Map.Entry> comparator, int pageSize)
IllegalArgumentException if pageSize is not greater than 0comparator - the comparator through which results will be orderedpageSize - the page sizepublic PagingPredicate(Predicate predicate, Comparator<Map.Entry> comparator, int pageSize)
IllegalArgumentException if pageSize is not greater than 0
throws IllegalArgumentException if inner predicate is also PagingPredicatepredicate - the inner predicate through which results will be filteredcomparator - the comparator through which results will be orderedpageSize - the page sizepublic Set<QueryableEntry> filter(QueryContext queryContext)
IndexAwarePredicate for filtering.filter in interface IndexAwarePredicatequeryContext - public boolean isIndexed(QueryContext queryContext)
IndexAwarePredicate for checking if indexed.isIndexed in interface IndexAwarePredicatequeryContext - public boolean apply(Map.Entry mapEntry)
public void reset()
public void nextPage()
public void previousPage()
public IterationType getIterationType()
public void setIterationType(IterationType iterationType)
public int getPage()
public void setPage(int page)
public int getPageSize()
public Predicate getPredicate()
public Comparator<Map.Entry> getComparator()
public Map.Entry getAnchor()
public void writeData(ObjectDataOutput out) throws IOException
DataSerializablewriteData in interface DataSerializableout - outputIOExceptionpublic void readData(ObjectDataInput in) throws IOException
DataSerializablereadData in interface DataSerializablein - inputIOExceptionpublic int getFactoryId()
IdentifiedDataSerializablegetFactoryId in interface IdentifiedDataSerializablepublic int getId()
IdentifiedDataSerializablegetId in interface IdentifiedDataSerializableCopyright © 2016 Hazelcast, Inc.. All Rights Reserved.