Skip to content

Instantly share code, notes, and snippets.

@vbmendes
Last active June 15, 2020 14:09
Show Gist options
  • Save vbmendes/19729cc88f6488b25e3c5eb9ec4ed2e2 to your computer and use it in GitHub Desktop.
Save vbmendes/19729cc88f6488b25e3c5eb9ec4ed2e2 to your computer and use it in GitHub Desktop.
public final class PaginationUtil {
private PaginationUtil(){}
public static <T> Page<T> paginateList(final Pageable pageable, List<T> list) {
int first = Math.min(new Long(pageable.getOffset()).intValue(), list.size());;
int last = Math.min(first + pageable.getPageSize(), list.size());
return new PageImpl<>(list.subList(first, last), pageable, list.size());
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment