private PageResponse getPageToOffset(int pageSize, int offset,
      Set<Resource> resources,
                                       Predicate predicate,
                                       ResourcePredicateEvaluator evaluator) {

    int                currentOffset = resources.size() - 1;
    Resource           next          = null;
    List<Resource>     pageResources = new LinkedList<>();
    LinkedList<Resource> filteredResources =
      getEvaluatedResources(new ResourceIterable(resources, predicate, evaluator));
    Iterator<Resource> iterator = filteredResources.descendingIterator();

    if (offset != -1) {
      // skip till offset
      while (currentOffset > offset && iterator.hasNext()) {
        next = iterator.next();
        --currentOffset;
      }
    }

    // get a page worth of resources
    for (int i = 0; i < pageSize && iterator.hasNext(); ++i) {
      pageResources.add(0, iterator.next());
      --currentOffset;
    }

    return new PageResponseImpl(pageResources,
        currentOffset + 1,
        iterator.hasNext() ? iterator.next() : null,
        next,
        filteredResources.size()
      );
  }
Get one page of resources from the given set of resources ending at the given offset.

@param pageSize   the page size
@param offset     the offset; -1 indicates the end of the resource set
@param resources  the set of resources
@param predicate  the predicate

@return a page response containing a page of resources
ambari-server/src/main/java/org/apache/ambari/server/controller/internal/ClusterControllerImpl.java