.map(link -> new ImmutablePair<>(link.getBodyName(), link.getPage(pages))) .filter(pair -> pair.getRight().isPresent()) .map(pair -> Utils.withRight(pair, pair.getRight().getAsInt())) .map(pair -> Utils.withRight( pair, uriInfo.getRequestUriBuilder() .map(pair -> Utils.withRight(pair, pair.getRight().build())) .collect(StreamUtils.toLinkedMap(Pair::getLeft, Pair::getRight)); responseContext.put(ResponseContextKeys.PAGINATION_LINKS_CONTEXT_KEY.getName(), bodyLinks);