diff --git a/li.strolch.agent/src/main/java/li/strolch/search/SearchResult.java b/li.strolch.agent/src/main/java/li/strolch/search/SearchResult.java index be39eea11..52b91e018 100644 --- a/li.strolch.agent/src/main/java/li/strolch/search/SearchResult.java +++ b/li.strolch.agent/src/main/java/li/strolch/search/SearchResult.java @@ -243,6 +243,22 @@ public class SearchResult { return Paging.asPage(this.stream.collect(Collectors.toList()), offset, limit); } + /** + * Returns a {@link Paging} element to use this object in paged results + * + * @param offset + * the element offset + * @param limit + * the limit per page + * @param dataSetSize + * The number of items before filtering + * + * @return the paging + */ + public Paging toPaging(int offset, int limit, long dataSetSize) { + return Paging.asPage(this.stream.collect(Collectors.toList()), offset, limit, dataSetSize); + } + /** * Returns the single element in the stream, or throws an {@link IllegalStateException} if the stream contains more * than 1 element, or the empty {@link Optional} diff --git a/li.strolch.utils/src/main/java/li/strolch/utils/collections/Paging.java b/li.strolch.utils/src/main/java/li/strolch/utils/collections/Paging.java index c20ac4d86..27a8f243f 100644 --- a/li.strolch.utils/src/main/java/li/strolch/utils/collections/Paging.java +++ b/li.strolch.utils/src/main/java/li/strolch/utils/collections/Paging.java @@ -31,7 +31,7 @@ public class Paging { private int limit; private int offset; private int size; - private int dataSetSize; + private long dataSetSize; private List input; private List page; @@ -89,7 +89,7 @@ public class Paging { /** * @return the size of all the data unfiltered */ - public int getDataSetSize() { + public long getDataSetSize() { return this.dataSetSize; } @@ -99,7 +99,7 @@ public class Paging { * @param dataSetSize * the size of all the data unfiltered */ - public void setDataSetSize(int dataSetSize) { + public void setDataSetSize(long dataSetSize) { this.dataSetSize = dataSetSize; } @@ -132,8 +132,29 @@ public class Paging { * @return a {@link Paging} instance from which the selected page (list) can be retrieved */ public static Paging asPage(List list, int offset, int limit) { + return asPage(list, offset, limit, 0); + } + + /** + * Creates a sub list of the input list with the given limit and offset + * + * @param list + * the list to paginate / create a window for + * @param offset + * where to start the sub list + * @param limit + * The number of items to return in each page/window + * @param dataSetSize + * The number of items before filtering + * @param + * the type of element in the list + * + * @return a {@link Paging} instance from which the selected page (list) can be retrieved + */ + public static Paging asPage(List list, int offset, int limit, long dataSetSize) { Paging paging = new Paging<>(); + paging.dataSetSize = dataSetSize; paging.limit = limit; paging.offset = offset;