-
Notifications
You must be signed in to change notification settings - Fork 36
minimal API changes for 0-based offsets #1482
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Changes from 2 commits
8985b64
749b0f2
ff6b919
8c47327
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -20,6 +20,7 @@ | |
| import jakarta.data.Limit; | ||
| import jakarta.data.Order; | ||
| import jakarta.data.Sort; | ||
| import jakarta.data.messages.Messages; | ||
| import jakarta.data.repository.First; | ||
| import jakarta.data.repository.OrderBy; | ||
|
|
||
|
|
@@ -223,9 +224,11 @@ static PageRequest beforeCursor(Cursor cursor, long pageNumber, int maxPageSize, | |
| Mode mode(); | ||
|
|
||
| /** | ||
| * Returns the page to be returned. | ||
| * Returns the requested page number. Page numbers begin with {@code 1}. | ||
| * | ||
| * @return the page to be returned. | ||
| * @return the requested page number | ||
| * @apiNote Page <em>numbers</em> are indexed from one; | ||
| * page {@linkplain #pageOffset offsets} are indexed from zero. | ||
| */ | ||
| long page(); | ||
|
|
||
|
|
@@ -259,16 +262,55 @@ static PageRequest beforeCursor(Cursor cursor, long pageNumber, int maxPageSize, | |
| boolean requestTotal(); | ||
|
|
||
| /** | ||
| * <p>Creates a new page request with the same pagination information, | ||
| * but with the specified page number.</p> | ||
| * Creates a new page request with the same pagination information, | ||
| * but with the specified page number. The first page number is {@code 1}. | ||
| * | ||
| * @param pageNumber the page number. | ||
| * @return a new instance of {@code PageRequest}. This method never returns | ||
| * {@code null}. | ||
| * @since 1.1 | ||
| * @apiNote Page <em>numbers</em> are indexed from one; | ||
| * page {@linkplain #pageOffset offsets} are indexed from zero. | ||
| */ | ||
| PageRequest page(long pageNumber); | ||
|
|
||
| /** | ||
| * Creates a new page request with the same pagination information, | ||
| * but with the given {@code offset}. | ||
| * <p> | ||
| * The offset is relative to the first page. An offset of {@code 0} | ||
| * requests the first page, and an offset of {@code 1} requests the | ||
| * second page. | ||
| * | ||
| * @return the offset of the requested page | ||
| * @throws IllegalStateException if the {@link #mode()} is not | ||
| * {@link Mode#OFFSET} | ||
| * @throws IllegalArgumentException if the {@code offset} is negative | ||
| * or {@link Long#MAX_VALUE} | ||
| * @since 1.1 | ||
| * | ||
| * @apiNote Page <em>offsets</em> are indexed from zero; | ||
| * page {@linkplain #page numbers} are indexed from one. | ||
| */ | ||
| default PageRequest pageOffset(long offset) { | ||
| if (mode() != Mode.OFFSET) { | ||
| throw new IllegalStateException( | ||
| Messages.get("014.mode.disallows.offset", mode())); | ||
| } | ||
|
|
||
| if (offset < 0) { | ||
| throw new IllegalArgumentException( | ||
| Messages.get("004.arg.negative", "offset")); | ||
| } | ||
|
|
||
| if (offset == Long.MAX_VALUE) { | ||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I am not sure about this one here.
Why is this not supported?
Member
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Of course it's a valid number. But an offset of Long.MAX_VALUE from the first result has a page number (Long.MAX_VALUE + 1) that is not representable as a positive
Member
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. 10^19 is an implausible number of rows. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You know, that's precisely how many rows I have. Make it work. |
||
| throw new IllegalArgumentException( | ||
| Messages.get("013.arg.invalid", "offset", offset)); | ||
| } | ||
|
|
||
| return page(offset + 1); | ||
| } | ||
|
|
||
| /** | ||
| * <p>Creates a new page request with the same pagination information, | ||
| * but with the specified maximum page size. When a page is retrieved from | ||
|
|
||
Uh oh!
There was an error while loading. Please reload this page.