コード例 #1
0
  @Test
  public void _09_결과모으기() {
    // collect로 모으기
    HashSet<String> result = words.stream().collect(HashSet::new, HashSet::add, HashSet::addAll);

    // 통계 뽑기(합계, 평균, 최댓값, 최솟값등..)
    IntSummaryStatistics summary =
        words.stream().collect(Collectors.summarizingInt(String::length));
    assertThat(summary.getCount(), is(9989L));
    assertThat(summary.getAverage(), is(3.9401341475623184D));
    assertThat(summary.getMax(), is(14));
  }
コード例 #2
0
 private static void printStatistic(
     GraalTruffleRuntime rt, String label, IntSummaryStatistics value) {
   rt.log(
       String.format(
           "  %-50s: count=%4d, sum=%8d, min=%8d, average=%12.2f, max=%8d ",
           label,
           value.getCount(),
           value.getSum(),
           value.getMin(),
           value.getAverage(),
           value.getMax()));
 }
  /** {@inheritDoc} */
  @Override
  public RequestAggregationValues aggregate(RequestCollector requests) {

    IntSummaryStatistics stats =
        requests
            .getReqTimestamps()
            .stream()
            .collect(
                Collectors.groupingBy(
                    timestamp -> DateUtils.round(new Date(timestamp), timestampAggregation),
                    Collectors.counting()))
            .values()
            .stream()
            .mapToInt(p -> toInt(p))
            .summaryStatistics();

    return new RequestAggregationValuesImpl(
        stats.getMin(), stats.getMax(), stats.getAverage(), stats.getSum(), stats.getCount());
  }