This class is designed to work with (though does not require) streams. For example, you can compute summary statistics on a stream of ints with:
IntSummaryStatistics stats = intStream.collect(IntSummaryStatistics::new,
IntSummaryStatistics::accept,
IntSummaryStatistics::combine);
IntSummaryStatistics
can be used as a
reduction
target for a stream. For example:
IntSummaryStatistics stats = people.stream()
.collect(Collectors.summarizingInt(Person::getDependents));
This computes, in a single pass, the count of people, as well as the minimum,
maximum, sum, and average of their number of dependents.
Implementation Note
This implementation is not thread safe. However, it is safe to use
Collectors.
on a parallel stream, because the parallel
implementation of Stream.
provides the necessary partitioning, isolation, and merging of results for
safe and efficient parallel execution.
This implementation does not check for overflow of the count or the sum.
Modifier and Type | Field and Description |
---|---|
private long | |
private int | |
private int | |
private long |
Access | Constructor and Description |
---|---|
public | IntSummaryStatistics()
Constructs an empty instance with zero count, zero sum,
|
public | IntSummaryStatistics(long
the count of values count, int the minimum value min, int the maximum value max, long the sum of all values sum)Constructs a non-empty instance with the specified |
Modifier and Type | Method and Description |
---|---|
public void | accept(int
the input value value)Implements java. Records a new value into the summary information |
public void | combine(IntSummaryStatistics
another other)IntSummaryStatistics Combines the state of another |
public final double | Returns: the arithmetic mean of values, or zero if noneReturns the arithmetic mean of values recorded, or zero if no values have been recorded. |
public final long | |
public final int | Returns: the maximum value, orInteger.MIN_VALUE if noneReturns the maximum value recorded, or |
public final int | Returns: the minimum value, orInteger.MAX_VALUE if noneReturns the minimum value recorded, or |
public final long | Returns: the sum of values, or zero if noneReturns the sum of values recorded, or zero if no values have been recorded. |
public String | toString()
Overrides java. Returns a non-empty string representation of this object suitable for debugging. |
count | back to summary |
---|---|
private long count |
max | back to summary |
---|---|
private int max |
min | back to summary |
---|---|
private int min |
sum | back to summary |
---|---|
private long sum |
IntSummaryStatistics | back to summary |
---|---|
public IntSummaryStatistics() Constructs an empty instance with zero count, zero sum,
|
IntSummaryStatistics | back to summary |
---|---|
public IntSummaryStatistics(long count, int min, int max, long sum) throws IllegalArgumentException Constructs a non-empty instance with the specified If If the arguments are inconsistent then an
API Note The enforcement of argument correctness means that the retrieved set of
recorded values obtained from a
|
accept | back to summary |
---|---|
public void accept(int value) Implements java. Records a new value into the summary information
|
combine | back to summary |
---|---|
public void combine(IntSummaryStatistics other) Combines the state of another
|
getAverage | back to summary |
---|---|
public final double getAverage() Returns the arithmetic mean of values recorded, or zero if no values have been recorded.
|
getCount | back to summary |
---|---|
public final long getCount() Returns the count of values recorded.
|
getMax | back to summary |
---|---|
public final int getMax() Returns the maximum value recorded, or
|
getMin | back to summary |
---|---|
public final int getMin() Returns the minimum value recorded, or
|
getSum | back to summary |
---|---|
public final long getSum() Returns the sum of values recorded, or zero if no values have been recorded.
|
toString | back to summary |
---|---|
public String toString() Overrides java. Returns a non-empty string representation of this object suitable for debugging. The exact presentation format is unspecified and may vary between implementations and versions.
|