private static <T, U, R> Collector<T, List<Tuple2<T, U>>, R> percentileCollector(
        Function<? super T, ? extends U> function,
        Comparator<? super U> comparator,
        Supplier<R> onEmpty,
        Function<T, R> onSingle,
        Function<List<Tuple2<T, U>>, R> finisher
    ) {
        return Collector.of(
            ArrayList::new,
            (l, v) -> l.add(tuple(v, function.apply(v))),
            (l1, l2) -> {
                l1.addAll(l2);
                return l1;
            },
            l -> {
                int size = l.size();

                if (size == 0)
                    return onEmpty.get();
                else if (size == 1)
                    return onSingle.apply(l.get(0).v1);

                l.sort(comparing(t -> t.v2, comparator));
                return finisher.apply(l);
            }
        );
    }
Get a {@link Collector} that calculates the derived <code>PERCENTILE_DISC(percentile)</code> function given a specific ordering, producing multiple results.
jOOL-java-8/src/main/java/org/jooq/lambda/Agg.java