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

    int currentOffset = 0;
    Resource previous      = null;
    Set<Resource> pageResources = new LinkedHashSet<>();
    LinkedList<Resource> filteredResources =
      getEvaluatedResources(new ResourceIterable(resources, predicate, evaluator));
    Iterator<Resource> iterator = filteredResources.iterator();

    // skip till offset
    while (currentOffset < offset && iterator.hasNext()) {
      previous = iterator.next();
      ++currentOffset;
    }

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

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

@param pageSize   the page size
@param offset     the offset
@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