UriBuilder uriBuilder;
if (originalList.getTotalSize() > (page +1 ) * pageControl.getPageSize()) {
int nextPage = page +1;
uriBuilder = uriInfo.getRequestUriBuilder(); // adds ?q, ?ps and ?category if needed
uriBuilder.replaceQueryParam("page",nextPage);
pColl.addLink(new Link("next",uriBuilder.build().toString()));
}
if (page > 0) {
int prevPage = page -1;
uriBuilder = uriInfo.getRequestUriBuilder(); // adds ?q, ?ps and ?category if needed
uriBuilder.replaceQueryParam("page",prevPage);
pColl.addLink(new Link("prev",uriBuilder.build().toString()));
}
// A link to the last page
if (!pageControl.isUnlimited()) {
uriBuilder = uriInfo.getRequestUriBuilder(); // adds ?q, ?ps and ?category if needed
uriBuilder.replaceQueryParam("page",lastPage);
pColl.addLink( new Link("last",uriBuilder.build().toString()));
}
// A link to the current page
uriBuilder = uriInfo.getRequestUriBuilder(); // adds ?q, ?ps and ?category if needed
pColl.addLink(new Link("current",uriBuilder.build().toString()));
builder.entity(pColl);
}