This class is designed to work with (though does not require) streams. For example, you can compute summary statistics on a stream of longs with:
LongSummaryStatistics stats = longStream.collect(LongSummaryStatistics::new,
LongSummaryStatistics::accept,
LongSummaryStatistics::combine);
LongSummaryStatistics
can be used as a
reduction
target for a stream. For example:
LongSummaryStatistics stats = people.stream()
.collect(Collectors.summarizingLong(Person::getAge));
This computes, in a single pass, the count of people, as well as the minimum,
maximum, sum, and average of their ages.
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 long | |
private long | |
private long |
Access | Constructor and Description |
---|---|
public | LongSummaryStatistics()
Constructs an empty instance with zero count, zero sum,
|
public | LongSummaryStatistics(long
the count of values count, long the minimum value min, long 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 |
public void | accept(long
the input value value)Implements java. Records a new |
public void | combine(LongSummaryStatistics
another other)LongSummaryStatistics 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 long | Returns: the maximum value, orLong.MIN_VALUE if noneReturns the maximum value recorded, or |
public final long | Returns: the minimum value, orLong.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 long max |
min | back to summary |
---|---|
private long min |
sum | back to summary |
---|---|
private long sum |
LongSummaryStatistics | back to summary |
---|---|
public LongSummaryStatistics() Constructs an empty instance with zero count, zero sum,
|
LongSummaryStatistics | back to summary |
---|---|
public LongSummaryStatistics(long count, long min, long 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
|
accept | back to summary |
---|---|
public void accept(long value) Implements java. Records a new
|
combine | back to summary |
---|---|
public void combine(LongSummaryStatistics 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 long getMax() Returns the maximum value recorded, or
|
getMin | back to summary |
---|---|
public final long 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.
|