Search in sources :

Example 1 with IntSummaryStatistics

use of java.util.IntSummaryStatistics in project jdk8u_jdk by JetBrains.

the class SummaryStatisticsTest method testIntStatistics.

public void testIntStatistics() {
    List<IntSummaryStatistics> instances = new ArrayList<>();
    instances.add(countTo(1000).stream().collect(Collectors.summarizingInt(i -> i)));
    instances.add(countTo(1000).stream().mapToInt(i -> i).summaryStatistics());
    instances.add(countTo(1000).parallelStream().collect(Collectors.summarizingInt(i -> i)));
    instances.add(countTo(1000).parallelStream().mapToInt(i -> i).summaryStatistics());
    for (IntSummaryStatistics stats : instances) {
        assertEquals(stats.getCount(), 1000);
        assertEquals(stats.getSum(), countTo(1000).stream().mapToInt(i -> i).sum());
        assertEquals(stats.getMax(), 1000);
        assertEquals(stats.getMin(), 1);
    }
}
Also used : ArrayList(java.util.ArrayList) IntSummaryStatistics(java.util.IntSummaryStatistics)

Example 2 with IntSummaryStatistics

use of java.util.IntSummaryStatistics in project intellij-community by JetBrains.

the class Main method test.

public static IntSummaryStatistics test() {
    IntSummaryStatistics stat = new IntSummaryStatistics();
    long limit = 50;
    for (int i = 0; i < 100; i++) {
        if (limit-- == 0)
            break;
        stat.accept(i);
    }
    return stat;
}
Also used : IntSummaryStatistics(java.util.IntSummaryStatistics)

Example 3 with IntSummaryStatistics

use of java.util.IntSummaryStatistics in project intellij-community by JetBrains.

the class Main method testOfArrayAsElement.

private static IntSummaryStatistics testOfArrayAsElement() {
    IntSummaryStatistics stat = new IntSummaryStatistics();
    for (Number[] nums : Arrays.<Number[]>asList(new Integer[] { 1, 2, 3 })) {
        int num = (int) nums[0];
        stat.accept(num);
    }
    return stat;
}
Also used : IntSummaryStatistics(java.util.IntSummaryStatistics)

Example 4 with IntSummaryStatistics

use of java.util.IntSummaryStatistics in project intellij-community by JetBrains.

the class Main method testOfArray.

private static IntSummaryStatistics testOfArray() {
    IntSummaryStatistics stat = new IntSummaryStatistics();
    for (Integer i : new Integer[] /*create array*/
    { 1, 2, 3 }) {
        int i1 = i;
        stat.accept(i1);
    }
    return stat;
}
Also used : IntSummaryStatistics(java.util.IntSummaryStatistics)

Example 5 with IntSummaryStatistics

use of java.util.IntSummaryStatistics in project intellij-community by JetBrains.

the class Main method testNested.

public static IntSummaryStatistics testNested() {
    IntSummaryStatistics stat = new IntSummaryStatistics();
    for (int limit = 0; limit < 20; limit++) {
        long limitInner = limit;
        for (String x = ""; ; x = x + limit) {
            if (limitInner-- == 0)
                break;
            int length = x.length();
            stat.accept(length);
        }
    }
    return stat;
}
Also used : IntSummaryStatistics(java.util.IntSummaryStatistics)

Aggregations

IntSummaryStatistics (java.util.IntSummaryStatistics)10 ArrayList (java.util.ArrayList)1 Arrays (java.util.Arrays)1 List (java.util.List)1 Map (java.util.Map)1 StringJoiner (java.util.StringJoiner)1 Supplier (java.util.function.Supplier)1 Collector (java.util.stream.Collector)1 Collectors (java.util.stream.Collectors)1