Collector / Collectors
Brian Goetz
brian.goetz at oracle.com
Thu Jun 20 09:58:15 PDT 2013
Spec and implementation:
/**
* Returns a new {@code Collector} described by the given {@code
supplier},
* {@code accumulator}, and {@code combiner} functions. The resulting
* {@code Collector} has the {@code
Collector.Characteristics.IDENTITY_FINISH}
* characteristic.
*
* @param supplier The supplier function for the new collector
* @param accumulator The accumulator function for the new collector
* @param combiner The combiner function for the new collector
* @param <T> The type of input elements for the new collector
* @param <R> The type of intermediate accumulation result, and
final result,
* for the new collector
* @return the new {@code Collector}
*/
static<T, R> Collector<T, R, R> of(Supplier<R> supplier,
BiConsumer<R, T> accumulator,
BinaryOperator<R> combiner) {
return new Collectors.CollectorImpl<>(supplier, accumulator,
combiner, Collectors.CH_ID);
}
/**
* Returns a new {@code Collector} described by the given {@code
supplier},
* {@code accumulator}, {@code combiner}, and {@code finisher}
functions.
*
* @param supplier The supplier function for the new collector
* @param accumulator The accumulator function for the new collector
* @param combiner The combiner function for the new collector
* @param <T> The type of input elements for the new collector
* @param <A> The intermediate accumulation type of the new collector
* @param <R> The final result type of the new collector
* @return the new {@code Collector}
*/
static<T, A, R> Collector<T, A, R> of(Supplier<A> supplier,
BiConsumer<A, T> accumulator,
BinaryOperator<A> combiner,
Function<A, R> finisher) {
return new Collectors.CollectorImpl<>(supplier, accumulator,
combiner, finisher, Collectors.CH_NOID);
}
On 6/20/2013 12:45 PM, Brian Goetz wrote:
> Several people have suggested adding:
>
> Collector.of(supplier, accumulator, combiner)
> Collector.of(supplier, accumulator, combiner, finisher)
>
> which is sensible and easy.
>
> On 6/18/2013 11:58 AM, Brian Goetz wrote:
>> I think I may (finally!) have a final API candidate for Collector /
>> Collectors. Updated docs here:
>>
>> http://cr.openjdk.java.net/~briangoetz/doctmp/doc/
>>
>> Salient recent changes:
>> - Incorporation of finishing function into Collector
>> - Renamings in Collector API
>> - Morph toStringBuilder, toStringJoiner into joining()
>> - Add prefix/suffix version of joining()
>> - Addition of summingBy{Int,Long,Double}
>> - Addition of averagingBy{Int,Long,Double}
>> - Rename toXxxSummaryStatistics to summarizingXxx
>> - no-see reducing, and minBy/maxBy collectors return Optional
>> - elimination of canned merger functions from API
>>
>> Please review the API and spec. I have set up a SurveyMonkey with the
>> usual password to collect review comments at:
>>
>> https://www.surveymonkey.com/s/3TTBJ7K
>>
>>
More information about the lambda-libs-spec-experts
mailing list