class 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();

}