用Java8收集统计信息

Nuñitode la Calzada:

我想在对一组数据进行分组后收集统计信息,但我不知道是否有可能

Map<String, DoubleSummaryStatistics> menuStatistics =

                menuPrices.parallelStream()
                        .collect(Collectors.groupingBy(cp -> dt1.format(cp.getUpdateDate())),
                                Collector.of(DoubleSummaryStatistics::new));

因为我有一些编译问题:

Multiple markers at this line
    - The method of(Supplier<R>, BiConsumer<R,T>, BinaryOperator<R>, Collector.Characteristics...) in the type Collector is not applicable for the arguments 
     (DoubleSummaryStatistics::new)
    - The constructed object of type DoubleSummaryStatistics is incompatible with the descriptor's return type: R
他们是 :

您需要使用Collectors.summarizingDouble(),假设您的类(的元素类型Stream)具有一些double要为其计算统计信息的属性:

Map<String, DoubleSummaryStatistics>
    menuStatistics =
        menuPrices.parallelStream()
                  .collect(Collectors.groupingBy(cp -> dt1.format(cp.getUpdateDate()),
                           Collectors.summarizingDouble(cp -> cp.getSomeDoubleValue())));

本文收集自互联网,转载请注明来源。

如有侵权,请联系 [email protected] 删除。

编辑于
0

我来说两句

0 条评论
登录 后参与评论

相关文章