E - element typepublic abstract class NavigableSetPager<E> extends Object
NavigableSet.
Instances are configured with a page size and a view order (ascending or descending).
Instances maintain a cursor position that anchors one "page" of consecutive items within the set. Each time
readCurrentPage() is invoked, the set is reacquired from getNavigableSet() and the
contents of the current page are read from it.
For navigation, nextPage() and prevPage() move to the next or previous page,
firstPage() and lastPage() jump to the first or last page.
After movement, hasNextPage() and hasPrevPage() indicate whether adjacent pages exist.
| Modifier and Type | Field and Description |
|---|---|
static int |
DEFAULT_PAGE_SIZE
Default page size (100).
|
| Constructor and Description |
|---|
NavigableSetPager() |
| Modifier and Type | Method and Description |
|---|---|
void |
firstPage()
Jump to the first page.
|
protected abstract NavigableSet<E> |
getNavigableSet()
Get the
NavigableSet through which to page. |
boolean |
hasNextPage()
Indicates that there are more results after the current page.
|
boolean |
hasPrevPage()
Indicates that there are more results before the current page.
|
boolean |
isDescending()
Get view ordering.
|
void |
lastPage()
Jump to the last page.
|
boolean |
nextPage()
Advance forward to the next page of results, if any.
|
boolean |
prevPage()
Advance backward to the previous page of results, if any.
|
List<E> |
readCurrentPage()
Read the contents of the current page.
|
void |
setCursor(E cursor)
Set the current cursor position, i.e., page anchor.
|
void |
setDescending(boolean descending)
Set view ordering.
|
void |
setFilter(Predicate<? super E> filter)
Filter which items in the set are returned.
|
void |
setPageSize(int pageSize)
Set the page size.
|
public static final int DEFAULT_PAGE_SIZE
setPageSize(),
Constant Field Valuespublic void setPageSize(int pageSize)
pageSize - maximum number of rows in a pageIllegalArgumentException - if pageSize is zero or lesspublic boolean isDescending()
public void setDescending(boolean descending)
descending - true for descending view, false for ascending viewpublic void setFilter(Predicate<? super E> filter)
Items that fail to pass the specified filter are omitted from the results
and do not contribute to the page total. Beware that a filter can reject arbitrarily
many items and therefore when using filters the time it takes to load a full page
is potentially unbounded.
filter - filter that accepts only the desired items, or null to accept allpublic boolean hasNextPage()
public boolean hasPrevPage()
public boolean nextPage()
This will advance to the next higher page of results if configured for an ascending view, or the next lower page of results if configured for a descending view.
After invoking this method, readCurrentPage() must be invoked for it to take effect.
Duplicate invocations of this method without an intervening call to readCurrentPage()
will have no effect and return false.
public boolean prevPage()
This will regress to be the next lower page of results if configured for an ascending view, or the next higher page of results if configured for a descending view.
After invoking this method, readCurrentPage() must be invoked for it to take effect.
Duplicate invocations of this method without an intervening call to readCurrentPage()
will have no effect and return false.
public void firstPage()
public void lastPage()
public void setCursor(E cursor)
The next page returned by readCurrentPage() will start at cursor,
inclusive for an ascending ordering or exclusive for a descending ordering.
The cursor must not be null unless the underlying NavigableSet supports null values.
cursor - new cursor position for the current pagepublic List<E> readCurrentPage()
The list is read starting from the current cursor position (inclusive for an ascending ordering, exclusive for a descending ordering).
If configured for an ascending view, the list will have ascending ordering; if configured for a descending view, the list will have descending ordering.
protected abstract NavigableSet<E> getNavigableSet()
NavigableSet through which to page.
This method is invoked anew each time readCurrentPage() is invoked.
Copyright © 2016. All rights reserved.