31
31
* @author Oliver Gierke
32
32
* @author Christoph Strobl
33
33
* @author Jens Schauder
34
+ * @author Jay Lee
34
35
* @since 2.4
35
36
*/
36
37
public abstract class PageableExecutionUtils {
@@ -54,19 +55,30 @@ public static <T> Page<T> getPage(List<T> content, Pageable pageable, LongSuppli
54
55
Assert .notNull (pageable , "Pageable must not be null" );
55
56
Assert .notNull (totalSupplier , "TotalSupplier must not be null" );
56
57
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
- }
58
+ if (pageable .isUnpaged ()) {
59
+ return new PageImpl <>(content , pageable , content .size ());
60
+ }
62
61
63
- return new PageImpl <>(content , pageable , totalSupplier .getAsLong ());
62
+ if (isFirstPage (pageable ) && isPartialPage (content , pageable )) {
63
+ return new PageImpl <>(content , pageable , content .size ());
64
64
}
65
65
66
- if (content . size () != 0 && pageable . getPageSize () > content . size ( )) {
66
+ if (isSubsequentPage ( pageable ) && ! content . isEmpty () && isPartialPage ( content , pageable )) {
67
67
return new PageImpl <>(content , pageable , pageable .getOffset () + content .size ());
68
68
}
69
69
70
70
return new PageImpl <>(content , pageable , totalSupplier .getAsLong ());
71
71
}
72
+
73
+ private static <T > boolean isPartialPage (List <T > content , Pageable pageable ) {
74
+ return pageable .getPageSize () > content .size ();
75
+ }
76
+
77
+ private static boolean isFirstPage (Pageable pageable ) {
78
+ return pageable .getOffset () == 0 ;
79
+ }
80
+
81
+ private static boolean isSubsequentPage (Pageable pageable ) {
82
+ return !isFirstPage (pageable );
83
+ }
72
84
}
0 commit comments