PagingUtil { public static String createLinkHeader(Page<?> page, URI uri) { requireNonNull(page, "Required non-null page"); requireNonNull(uri, "Required non-null uri"); final ArrayList<Pair<String, Page.PageRef>> pageRefs = new ArrayList<>(4); pageRefs.add(Pair.of("first", page.getFirstPageRef())); pageRefs.add(Pair.of("last", page.getLastPageRef())); if (page.hasPreviousPage()) { pageRefs.add(Pair.of("prev", page.getPreviousPageRef())); } if (page.hasNextPage()) { pageRefs.add(Pair.of("next", page.getNextPageRef())); } final UriBuilder ub = UriBuilder.fromUri(uri); return pageRefs .stream() .map( refPair -> format( "<%s>; rel=\"%s\"", ub.clone() .replaceQueryParam("skipCount", refPair.second.getItemsBefore()) .replaceQueryParam("maxItems", refPair.second.getPageSize()) .build() .toString(), refPair.first)) .collect(joining(LINK_HEADER_SEPARATOR)); } private  PagingUtil(); static String createLinkHeader(Page<?> page, URI uri); static Map<String, String> parseLinkHeader(String linkHeader);  }
@Test public void testCreatingLinksHeader() throws Exception { final Page<String> page = new Page<>(asList("item3", "item4", "item5"), 3, 3, 7); final URI srcUri = URI.create("http: final String linkHeader = createLinkHeader(page, srcUri); final String[] expLinks = ("<http: + "<http: + "<http: + "<http: .split(", "); assertEqualsNoOrder(linkHeader.split(", "), expLinks); }