DATACMNS-867 - Improvements in Chunk and PageImpl.
Chunk now rejects null Pageables. Improved total calculation in PageImpl by using ….toOptional().
This commit is contained in:
@@ -49,6 +49,7 @@ abstract class Chunk<T> implements Slice<T>, Serializable {
|
||||
public Chunk(List<T> content, Pageable pageable) {
|
||||
|
||||
Assert.notNull(content, "Content must not be null!");
|
||||
Assert.notNull(pageable, "Pageable must not be null!");
|
||||
|
||||
this.content.addAll(content);
|
||||
this.pageable = pageable;
|
||||
|
||||
@@ -16,7 +16,6 @@
|
||||
package org.springframework.data.domain;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Optional;
|
||||
import java.util.function.Function;
|
||||
|
||||
/**
|
||||
@@ -45,10 +44,7 @@ public class PageImpl<T> extends Chunk<T> implements Page<T> {
|
||||
super(content, pageable);
|
||||
|
||||
this.pageable = pageable;
|
||||
|
||||
Optional<Pageable> foo = pageable.isPaged() ? Optional.of(pageable) : Optional.empty();
|
||||
|
||||
this.total = foo.filter(it -> !content.isEmpty())//
|
||||
this.total = pageable.toOptional().filter(it -> !content.isEmpty())//
|
||||
.filter(it -> it.getOffset() + it.getPageSize() > total)//
|
||||
.map(it -> it.getOffset() + content.size())//
|
||||
.orElse(total);
|
||||
|
||||
Reference in New Issue
Block a user