|
17 | 17 |
|
18 | 18 | import java.util.Iterator; |
19 | 19 |
|
| 20 | +/** A generic interface for pagination through large sets of items of type <T>. */ |
20 | 21 | public interface Page<T> extends Iterable<T> { |
| 22 | + /** An iterator over the items in this page. */ |
21 | 23 | public Iterator<T> iterator(); |
| 24 | + |
| 25 | + /** The start position of this page within all possible items. For result sets |
| 26 | + * this is the position of the first result within the result set. |
| 27 | + * @return the start position |
| 28 | + */ |
22 | 29 | public long getStart(); |
| 30 | + |
| 31 | + /** The page size which is the maximum number of items allowed in one page. |
| 32 | + * @return the page size */ |
23 | 33 | public long getPageSize(); |
| 34 | + |
| 35 | + /** The total count (potentially an estimate) of all possible items in the set. |
| 36 | + * For result sets this is the number of items within the result set. |
| 37 | + * For search result sets this is the estimated number of matching items. |
| 38 | + * @return the total count of possible items */ |
24 | 39 | public long getTotalSize(); |
| 40 | + |
| 41 | + /** The count of items in this page, which is always less than getPageSize(). |
| 42 | + * If ({@link #getTotalSize()} - {@link #getStart()}) > {@link #getPageSize()} |
| 43 | + * then size() == getPageSize(). |
| 44 | + * @return the count of items in this page |
| 45 | + */ |
25 | 46 | public long size(); |
| 47 | + |
| 48 | + |
| 49 | + /** The number of pages covering all possible items. |
| 50 | + * @return the number of pages. Literally, |
| 51 | + * <pre>{@code (long) Math.ceil((double) getTotalSize() / (double) getPageSize()); }</pre> |
| 52 | + */ |
26 | 53 | public long getTotalPages(); |
| 54 | + |
| 55 | + /** Whether there are any items in this page. |
| 56 | + * @return true if {@code size() > 0; } |
| 57 | + */ |
27 | 58 | public boolean hasContent(); |
| 59 | + |
| 60 | + /** Whether there are any items in the next page. |
| 61 | + * @return true if {@code getPageNumber() < getTotalPages(); } |
| 62 | + */ |
28 | 63 | public boolean hasNextPage(); |
| 64 | + |
| 65 | + /** Whether there is a previous page. |
| 66 | + * @return true if {@code getPageNumber() > 0 } |
| 67 | + */ |
29 | 68 | public boolean hasPreviousPage(); |
| 69 | + |
| 70 | + /** The page number within the count of all possible pages. |
| 71 | + * @return {@code (long) Math.floor((double) start / (double) getPageSize()) + 1; } |
| 72 | + */ |
30 | 73 | public long getPageNumber(); |
| 74 | + |
| 75 | + /** @return true if {@code getPageNumber() == 1 } |
| 76 | + */ |
31 | 77 | public boolean isFirstPage(); |
| 78 | + |
| 79 | + /** @return true if {@code getPageNumber() == getTotalPages() } |
| 80 | + */ |
32 | 81 | public boolean isLastPage(); |
33 | 82 | } |
0 commit comments