private static <T, R extends ResultPage<T>> Collector<T, List<T>, R> createCollector(
            final PageRequest pageRequest,
            final BiFunction<List<T>, PageResponse, R> resultPageFactory) {

        // Explicit typing needed for GWT
        return new Collector<T, List<T>, R>() {
            long counter = 0L;

            @Override
            public Supplier<List<T>> supplier() {
                return ArrayList::new;
            }

            @Override
            public BiConsumer<List<T>, T> accumulator() {
                return (accumulator, item) -> {
                    if (pageRequest == null
                        || (
                                counter >= pageRequest.getOffset() &&
                                accumulator.size() < pageRequest.getLength())) {
                        accumulator.add(item);
                    }
                    counter++;
                };
            }

            @Override
            public BinaryOperator<List<T>> combiner() {
                return (left, right) -> {
                    left.addAll(right);
                    return left;
                };
            }

            @Override
            public Function<List<T>, R> finisher() {
                return accumulator ->
                        resultPageFactory.apply(
                                accumulator,
                                new PageResponse(
                                        pageRequest != null
                                                ? pageRequest.getOffset()
                                                : 0,
                                        accumulator.size(),
                                        counter,
                                        true));
            }

            @Override
            public Set<Characteristics> characteristics() {
                return Collections.emptySet();
            }
        };
    }
Used for filter queries (maybe bounded).
stroom-util-shared/src/main/java/stroom/util/shared/ResultPage.java