public static <T> ResultPage<T> createCriterialBasedList(final List<T> realList,
                                                             final BaseCriteria baseCriteria) {
        List<T> results = realList;
        final PageRequest pageRequest = baseCriteria.getPageRequest();
        boolean moreToFollow = false;
        Long totalSize = null;
        final long offset = pageRequest != null && pageRequest.getOffset() != null
                ? pageRequest.getOffset()
                : 0;

        if (pageRequest != null && pageRequest.getLength() != null) {
            // All our queries are + 1 on the limit so that we know there is
            // more to come
            final int overflow = results.size() - pageRequest.getLength();
            moreToFollow = overflow > 0;

            if (moreToFollow) {
                if (overflow > 1) {
                    // Here we check that if the query was supposed to be limited
                    // make sure we have
                    // get to process more that 1 + that limit. If this fails it
                    // will be a coding error
                    // or not applying the limit.
                    throw new IllegalStateException(
                            "For some reason we returned more rows that we were limited to. " +
                            "Did you apply the restriction criteria?");
                }

                // All our queries are + 1 to we need to remove the last element
                results = results.subList(0, results.size() - 1);

            } else {
                // If we have not been given the total size see if we can work it out
                // based on hitting the end
                totalSize = offset + results.size();
            }
        }

        final PageResponse pageResponse = new PageResponse(
                offset,
                results.size(),
                totalSize,
                !moreToFollow);
        return new ResultPage<>(results, pageResponse);
    }
Used for filter queries (maybe bounded).
stroom-util-shared/src/main/java/stroom/util/shared/ResultPage.java