Skip to content
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

add Cursor.elements() #496

Merged
merged 1 commit into from
Feb 28, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions api/src/main/java/jakarta/data/page/KeysetCursor.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package jakarta.data.page;

import java.util.Arrays;
import java.util.List;

/**
* Built-in implementation of Cursor for keyset pagination.
Expand Down Expand Up @@ -60,6 +61,11 @@ public int size() {
return keyset.length;
}

@Override
public List<?> elements() {
return List.of(keyset);
}

@Override
public String toString() {
return new StringBuilder(27).append("Cursor@").append(Integer.toHexString(hashCode()))
Expand Down
8 changes: 8 additions & 0 deletions api/src/main/java/jakarta/data/page/PageRequest.java
Original file line number Diff line number Diff line change
Expand Up @@ -487,6 +487,14 @@ interface Cursor {
*/
int size();

/**
* An unmodifiable list of values in the keyset.
*
* @return an unmodifiable list containing the
* ordered values
*/
List<?> elements();

/**
* String representation of the keyset cursor, including the number of
* key values in the cursor but not the values themselves.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,7 +153,7 @@ void shouldBeEqualWithSameKeysetValues() {
PageRequest.Cursor cursor1 = new KeysetCursor("keyval1", '2', 3);
PageRequest.Cursor cursor2 = new KeysetCursor("keyval2", '2', 3);
PageRequest.Cursor cursor3 = new KeysetCursor("keyval1", '2');
PageRequest.Cursor cursor4 = new Pagination.Cursor() {
PageRequest.Cursor cursor4 = new PageRequest.Cursor() {
private final Object[] keyset = new Object[] { "keyval1", '2', 3 };

@Override
Expand All @@ -165,6 +165,11 @@ public Object getKeysetElement(int index) {
public int size() {
return keyset.length;
}

@Override
public List<?> elements() {
return List.of(keyset);
}
};

assertSoftly(softly -> {
Expand Down