Skip to content

Commit d63f5f3

Browse files
committed
Refactor PageableExecutionUtils.
TICKET: GH-3103.
1 parent 0a603f2 commit d63f5f3

File tree

1 file changed

+18
-7
lines changed

1 file changed

+18
-7
lines changed

src/main/java/org/springframework/data/support/PageableExecutionUtils.java

+18-7
Original file line numberDiff line numberDiff line change
@@ -54,19 +54,30 @@ public static <T> Page<T> getPage(List<T> content, Pageable pageable, LongSuppli
5454
Assert.notNull(pageable, "Pageable must not be null");
5555
Assert.notNull(totalSupplier, "TotalSupplier must not be null");
5656

57-
if (pageable.isUnpaged() || pageable.getOffset() == 0) {
58-
59-
if (pageable.isUnpaged() || pageable.getPageSize() > content.size()) {
60-
return new PageImpl<>(content, pageable, content.size());
61-
}
57+
if (pageable.isUnpaged()) {
58+
return new PageImpl<>(content, pageable, content.size());
59+
}
6260

63-
return new PageImpl<>(content, pageable, totalSupplier.getAsLong());
61+
if (isFirstPage(pageable) && isPartialPage(content, pageable)) {
62+
return new PageImpl<>(content, pageable, content.size());
6463
}
6564

66-
if (content.size() != 0 && pageable.getPageSize() > content.size()) {
65+
if (isSubsequentPage(pageable) && !content.isEmpty() && isPartialPage(content, pageable)) {
6766
return new PageImpl<>(content, pageable, pageable.getOffset() + content.size());
6867
}
6968

7069
return new PageImpl<>(content, pageable, totalSupplier.getAsLong());
7170
}
71+
72+
private static <T> boolean isPartialPage(List<T> content, Pageable pageable) {
73+
return pageable.getPageSize() > content.size();
74+
}
75+
76+
private static boolean isFirstPage(Pageable pageable) {
77+
return pageable.getOffset() == 0;
78+
}
79+
80+
private static boolean isSubsequentPage(Pageable pageable) {
81+
return !isFirstPage(pageable);
82+
}
7283
}

0 commit comments

Comments
 (0)