Skip to content

Commit e449e31

Browse files
committed
update javadoc to emphasize that getTotalSize is an estimate and getPageNumber is based on that estimate and thus may change as the estimate is updated to be more accurate
1 parent 7870573 commit e449e31

File tree

1 file changed

+32
-11
lines changed

1 file changed

+32
-11
lines changed

src/main/java/com/marklogic/client/Page.java

Lines changed: 32 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -46,10 +46,20 @@ public interface Page<T> extends Iterable<T> {
4646
* @return the page size */
4747
public long getPageSize();
4848

49-
/** The total count (potentially an estimate) of all possible items in the set.
50-
* For result sets this is the number of items within the result set.
51-
* For search result sets this is the estimated number of matching items.
52-
* @return the total count of possible items */
49+
/** The total count (most likely an
50+
* <a href="http://docs.marklogic.com/xdmp:estimate">estimate</a>) of all
51+
* possible items in the set. If this number is larger than getPageSize()
52+
* then hasNextPage() should be true and you most likely can retrieve
53+
* additional pages to get the remaining available items in the set.
54+
* For result sets this is the number of items within the result set.
55+
* For search result sets this is the estimated number of matching items.
56+
* That means you may see this number change as you paginate through a
57+
* search result set and the server updates the estimate with something
58+
* more accurate.
59+
* @return the total count of possible items
60+
* @see <a href="http://docs.marklogic.com/xdmp:estimate">xdmp:estimate</a>
61+
* @see <a href="http://docs.marklogic.com/search:estimate">search:estimate</a>
62+
*/
5363
public long getTotalSize();
5464

5565
/** The count of items in this page, which is always less than getPageSize().
@@ -60,9 +70,16 @@ public interface Page<T> extends Iterable<T> {
6070
public long size();
6171

6272

63-
/** The number of pages covering all possible items.
64-
* @return the number of pages. Literally,
65-
* <pre>{@code (long) Math.ceil((double) getTotalSize() / (double) getPageSize()); }</pre>
73+
/** The number of pages covering all possible items. Since this is calculated
74+
* based on {@link #getTotalSize()}, it is often an
75+
* <a href="http://docs.marklogic.com/xdmp:estimate">estimate</a>
76+
* just like getTotalSize().
77+
* That means you may see this number change as you paginate through a search
78+
* result set and the server updates the estimate with something more accurate.
79+
* @return the number of pages. In pseudo-code:
80+
* <pre>{@code if ( getPageSize() == 0 ) return 0;
81+
*Math.ceil( getTotalSize() / getPageSize() );
82+
* }</pre>
6683
*/
6784
public long getTotalPages();
6885

@@ -81,16 +98,20 @@ public interface Page<T> extends Iterable<T> {
8198
*/
8299
public boolean hasPreviousPage();
83100

84-
/** The page number within the count of all possible pages.
85-
* @return {@code (long) Math.floor((double) start / (double) getPageSize()) + 1; }
101+
/** The page number within the count of all possible pages.
102+
* @return the page number. In pseudo-code:
103+
* <pre>{@code if ( getPageSize() == 0 ) return 0;
104+
*if ( getStart() % getPageSize() == 0 ) return getStart() / getPageSize();
105+
*else return Math.floor(getStart() / getPageSize()) + 1;
106+
* }</pre>
86107
*/
87108
public long getPageNumber();
88109

89-
/** @return true if {@code getPageNumber() == 1 }
110+
/** @return true if {@code getPageSize()==0 or getPageNumber()==1 }
90111
*/
91112
public boolean isFirstPage();
92113

93-
/** @return true if {@code getPageNumber() == getTotalPages() }
114+
/** @return true if {@code getPageSize()==0 or getPageNumber()==getTotalPages() }
94115
*/
95116
public boolean isLastPage();
96117
}

0 commit comments

Comments
 (0)