From 9ab34d867231e6fae49b79cacdc5714533f5b960 Mon Sep 17 00:00:00 2001 From: Jens Schauder Date: Mon, 1 Jul 2024 12:57:57 +0200 Subject: [PATCH] Further refactoring of PageableExecutionUtils. Removing `isSubsequentPage`. It is another name for !isFirstPage suggesting a different meaning which isn't there. Extracting `if (isFirstPage(pageable)) {`, further structuring the decision tree. See #3103 Original pull request #3113 --- .../data/support/PageableExecutionUtils.java | 14 ++++++-------- 1 file changed, 6 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/springframework/data/support/PageableExecutionUtils.java b/src/main/java/org/springframework/data/support/PageableExecutionUtils.java index 3adfb6989..91ec67332 100644 --- a/src/main/java/org/springframework/data/support/PageableExecutionUtils.java +++ b/src/main/java/org/springframework/data/support/PageableExecutionUtils.java @@ -59,12 +59,13 @@ public abstract class PageableExecutionUtils { return new PageImpl<>(content, pageable, content.size()); } - if (isFirstPage(pageable) && isPartialPage(content, pageable)) { - return new PageImpl<>(content, pageable, content.size()); - } + if (isPartialPage(content, pageable)) { - if (isSubsequentPage(pageable) && !content.isEmpty() && isPartialPage(content, pageable)) { - return new PageImpl<>(content, pageable, pageable.getOffset() + content.size()); + if (isFirstPage(pageable)) { + return new PageImpl<>(content, pageable, content.size()); + } else if ( !content.isEmpty()) { + return new PageImpl<>(content, pageable, pageable.getOffset() + content.size()); + } } return new PageImpl<>(content, pageable, totalSupplier.getAsLong()); @@ -78,7 +79,4 @@ public abstract class PageableExecutionUtils { return pageable.getOffset() == 0; } - private static boolean isSubsequentPage(Pageable pageable) { - return !isFirstPage(pageable); - } }