28
29 /**
30 * A state object for collecting statistics such as count, min, max, sum, and
31 * average.
32 *
33 * <p>This class is designed to work with (though does not require)
34 * {@linkplain java.util.stream streams}. For example, you can compute
35 * summary statistics on a stream of ints with:
36 * <pre> {@code
37 * IntSummaryStatistics stats = intStream.collect(IntSummaryStatistics::new,
38 * IntSummaryStatistics::accept,
39 * IntSummaryStatistics::combine);
40 * }</pre>
41 *
42 * <p>{@code IntSummaryStatistics} can be used as a
43 * {@linkplain java.util.stream.Stream#reduce(java.util.function.BinaryOperator) reduction}
44 * target for a {@linkplain java.util.stream.Stream stream}. For example:
45 *
46 * <pre> {@code
47 * IntSummaryStatistics stats = people.stream()
48 * .collect(Collectors.toIntSummaryStatistics(Person::getDependents));
49 *}</pre>
50 *
51 * This computes, in a single pass, the count of people, as well as the minimum,
52 * maximum, sum, and average of their number of dependents.
53 *
54 * @implNote This implementation is not thread safe. However, it is safe to use
55 * {@link java.util.stream.Collectors#toIntSummaryStatistics(java.util.function.ToIntFunction)
56 * Collectors.toIntStatistics()} on a parallel stream, because the parallel
57 * implementation of {@link java.util.stream.Stream#collect Stream.collect()}
58 * provides the necessary partitioning, isolation, and merging of results for
59 * safe and efficient parallel execution.
60 *
61 * <p>This implementation does not check for overflow of the sum.
62 * @since 1.8
63 */
64 public class IntSummaryStatistics implements IntConsumer {
65 private long count;
66 private long sum;
67 private int min = Integer.MAX_VALUE;
68 private int max = Integer.MIN_VALUE;
69
70 /**
71 * Construct an empty instance with zero count, zero sum,
72 * {@code Integer.MAX_VALUE} min, {@code Integer.MIN_VALUE} max and zero
73 * average.
74 */
75 public IntSummaryStatistics() { }
|
28
29 /**
30 * A state object for collecting statistics such as count, min, max, sum, and
31 * average.
32 *
33 * <p>This class is designed to work with (though does not require)
34 * {@linkplain java.util.stream streams}. For example, you can compute
35 * summary statistics on a stream of ints with:
36 * <pre> {@code
37 * IntSummaryStatistics stats = intStream.collect(IntSummaryStatistics::new,
38 * IntSummaryStatistics::accept,
39 * IntSummaryStatistics::combine);
40 * }</pre>
41 *
42 * <p>{@code IntSummaryStatistics} can be used as a
43 * {@linkplain java.util.stream.Stream#reduce(java.util.function.BinaryOperator) reduction}
44 * target for a {@linkplain java.util.stream.Stream stream}. For example:
45 *
46 * <pre> {@code
47 * IntSummaryStatistics stats = people.stream()
48 * .collect(Collectors.summarizingInt(Person::getDependents));
49 *}</pre>
50 *
51 * This computes, in a single pass, the count of people, as well as the minimum,
52 * maximum, sum, and average of their number of dependents.
53 *
54 * @implNote This implementation is not thread safe. However, it is safe to use
55 * {@link java.util.stream.Collectors#summarizingInt(java.util.function.ToIntFunction)
56 * Collectors.toIntStatistics()} on a parallel stream, because the parallel
57 * implementation of {@link java.util.stream.Stream#collect Stream.collect()}
58 * provides the necessary partitioning, isolation, and merging of results for
59 * safe and efficient parallel execution.
60 *
61 * <p>This implementation does not check for overflow of the sum.
62 * @since 1.8
63 */
64 public class IntSummaryStatistics implements IntConsumer {
65 private long count;
66 private long sum;
67 private int min = Integer.MAX_VALUE;
68 private int max = Integer.MIN_VALUE;
69
70 /**
71 * Construct an empty instance with zero count, zero sum,
72 * {@code Integer.MAX_VALUE} min, {@code Integer.MIN_VALUE} max and zero
73 * average.
74 */
75 public IntSummaryStatistics() { }
|