Skip to content

Commit bc28a6b

Browse files
committed
DATACMNS-867 - Improvements in Chunk and PageImpl.
Chunk now rejects null Pageables. Improved total calculation in PageImpl by using ….toOptional().
1 parent 93bb3d2 commit bc28a6b

File tree

2 files changed

+2
-5
lines changed

2 files changed

+2
-5
lines changed

src/main/java/org/springframework/data/domain/Chunk.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ abstract class Chunk<T> implements Slice<T>, Serializable {
4949
public Chunk(List<T> content, Pageable pageable) {
5050

5151
Assert.notNull(content, "Content must not be null!");
52+
Assert.notNull(pageable, "Pageable must not be null!");
5253

5354
this.content.addAll(content);
5455
this.pageable = pageable;

src/main/java/org/springframework/data/domain/PageImpl.java

Lines changed: 1 addition & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616
package org.springframework.data.domain;
1717

1818
import java.util.List;
19-
import java.util.Optional;
2019
import java.util.function.Function;
2120

2221
/**
@@ -45,10 +44,7 @@ public PageImpl(List<T> content, Pageable pageable, long total) {
4544
super(content, pageable);
4645

4746
this.pageable = pageable;
48-
49-
Optional<Pageable> foo = pageable.isPaged() ? Optional.of(pageable) : Optional.empty();
50-
51-
this.total = foo.filter(it -> !content.isEmpty())//
47+
this.total = pageable.toOptional().filter(it -> !content.isEmpty())//
5248
.filter(it -> it.getOffset() + it.getPageSize() > total)//
5349
.map(it -> it.getOffset() + content.size())//
5450
.orElse(total);

0 commit comments

Comments
 (0)