mirror of
https://github.com/DSpace/DSpace.git
synced 2025-10-07 18:14:26 +00:00
minor refactoring
This commit is contained in:
@@ -98,6 +98,7 @@ import org.springframework.data.domain.PageRequest;
|
|||||||
import org.springframework.data.domain.Pageable;
|
import org.springframework.data.domain.Pageable;
|
||||||
import org.springframework.hateoas.Link;
|
import org.springframework.hateoas.Link;
|
||||||
import org.springframework.security.access.AccessDeniedException;
|
import org.springframework.security.access.AccessDeniedException;
|
||||||
|
import org.springframework.security.core.parameters.P;
|
||||||
import org.springframework.stereotype.Component;
|
import org.springframework.stereotype.Component;
|
||||||
import org.springframework.web.multipart.MultipartFile;
|
import org.springframework.web.multipart.MultipartFile;
|
||||||
|
|
||||||
@@ -151,16 +152,10 @@ public class Utils {
|
|||||||
public <T> Page<T> getPage(List<T> fullContents, @Nullable Pageable optionalPageable) {
|
public <T> Page<T> getPage(List<T> fullContents, @Nullable Pageable optionalPageable) {
|
||||||
Pageable pageable = getPageable(optionalPageable);
|
Pageable pageable = getPageable(optionalPageable);
|
||||||
int total = fullContents.size();
|
int total = fullContents.size();
|
||||||
List<T> pageContent = null;
|
|
||||||
if (pageable.getOffset() > total) {
|
if (pageable.getOffset() > total) {
|
||||||
throw new PaginationException(total);
|
throw new PaginationException(total);
|
||||||
} else {
|
} else {
|
||||||
if (pageable.getOffset() + pageable.getPageSize() > total) {
|
List<T> pageContent = getListSlice(fullContents, pageable);
|
||||||
pageContent = fullContents.subList(Math.toIntExact(pageable.getOffset()), total);
|
|
||||||
} else {
|
|
||||||
pageContent = fullContents.subList(Math.toIntExact(pageable.getOffset()),
|
|
||||||
Math.toIntExact(pageable.getOffset()) + pageable.getPageSize());
|
|
||||||
}
|
|
||||||
return new PageImpl<>(pageContent, pageable, total);
|
return new PageImpl<>(pageContent, pageable, total);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
@@ -175,20 +170,32 @@ public class Utils {
|
|||||||
public <T> List<T> getPageObjectList(List<T> fullList, @Nullable Pageable optionalPageable) {
|
public <T> List<T> getPageObjectList(List<T> fullList, @Nullable Pageable optionalPageable) {
|
||||||
Pageable pageable = getPageable(optionalPageable);
|
Pageable pageable = getPageable(optionalPageable);
|
||||||
int total = fullList.size();
|
int total = fullList.size();
|
||||||
List<T> pageContent = null;
|
|
||||||
if (pageable.getOffset() > total) {
|
if (pageable.getOffset() > total) {
|
||||||
throw new PaginationException(total);
|
throw new PaginationException(total);
|
||||||
} else {
|
} else {
|
||||||
if (pageable.getOffset() + pageable.getPageSize() > total) {
|
return getListSlice(fullList, pageable);
|
||||||
pageContent = fullList.subList(Math.toIntExact(pageable.getOffset()), total);
|
|
||||||
} else {
|
|
||||||
pageContent = fullList.subList(Math.toIntExact(pageable.getOffset()),
|
|
||||||
Math.toIntExact(pageable.getOffset()) + pageable.getPageSize());
|
|
||||||
}
|
|
||||||
return pageContent;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* Returns the list elements required for the page
|
||||||
|
* @param fullList the complete list of objects
|
||||||
|
* @param pageable
|
||||||
|
* @return list of page objects
|
||||||
|
* @param <T>
|
||||||
|
*/
|
||||||
|
private <T> List<T> getListSlice(List<T> fullList, Pageable pageable) {
|
||||||
|
int total = fullList.size();
|
||||||
|
List<T> pageContent = null;
|
||||||
|
if (pageable.getOffset() + pageable.getPageSize() > total) {
|
||||||
|
pageContent = fullList.subList(Math.toIntExact(pageable.getOffset()), total);
|
||||||
|
} else {
|
||||||
|
pageContent = fullList.subList(Math.toIntExact(pageable.getOffset()),
|
||||||
|
Math.toIntExact(pageable.getOffset()) + pageable.getPageSize());
|
||||||
|
}
|
||||||
|
return pageContent;
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Convenience method to get a default pageable instance if needed.
|
* Convenience method to get a default pageable instance if needed.
|
||||||
*
|
*
|
||||||
|
Reference in New Issue
Block a user