This class is designed to work with (though does not require) streams. For example, you can compute summary statistics on a stream of doubles with:
DoubleSummaryStatistics stats = doubleStream.collect(DoubleSummaryStatistics::new,
DoubleSummaryStatistics::accept,
DoubleSummaryStatistics::combine);
DoubleSummaryStatistics
can be used as a
reduction
target for a stream. For example:
DoubleSummaryStatistics stats = people.stream()
.collect(Collectors.summarizingDouble(Person::getWeight));
This computes, in a single pass, the count of people, as well as the minimum,
maximum, sum, and average of their weights.
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.
Modifier and Type | Field and Description |
---|---|
private long | |
private double | |
private double | |
private double | |
private double | |
private double |
Access | Constructor and Description |
---|---|
public | DoubleSummaryStatistics()
Constructs an empty instance with zero count, zero sum,
|
public | DoubleSummaryStatistics(long
the count of values count, double the minimum value min, double the maximum value max, double the sum of all values sum)Constructs a non-empty instance with the specified |
Modifier and Type | Method and Description |
---|---|
public void | accept(double
the input value value)Implements java. Records another value into the summary information. |
public void | combine(DoubleSummaryStatistics
another other)DoubleSummaryStatistics 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 double | Returns: the maximum recorded value,Double.NaN if any recorded
value was NaN or Double.NEGATIVE_INFINITY if no values were
recordedReturns the maximum recorded value, |
public final double | Returns: the minimum recorded value,Double.NaN if any recorded
value was NaN or Double.POSITIVE_INFINITY if no values were
recordedReturns the minimum recorded value, |
public final double | Returns: the sum of values, or zero if noneReturns the sum of values recorded, or zero if no values have been recorded. |
private void | sumWithCompensation(double value)
Incorporate a new double value using Kahan summation / compensated summation. |
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 double max |
min | back to summary |
---|---|
private double min |
simpleSum | back to summary |
---|---|
private double simpleSum |
sum | back to summary |
---|---|
private double sum |
sumCompensation | back to summary |
---|---|
private double sumCompensation |
DoubleSummaryStatistics | back to summary |
---|---|
public DoubleSummaryStatistics() Constructs an empty instance with zero count, zero sum,
|
DoubleSummaryStatistics | back to summary |
---|---|
public DoubleSummaryStatistics(long count, double min, double max, double 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(double value) Implements java. Records another value into the summary information.
|
combine | back to summary |
---|---|
public void combine(DoubleSummaryStatistics 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. The computed average can vary numerically and have the
special case behavior as computing the sum; see API Note Values sorted by increasing absolute magnitude tend to yield more accurate results.
|
getCount | back to summary |
---|---|
public final long getCount() Return the count of values recorded.
|
getMax | back to summary |
---|---|
public final double getMax() Returns the maximum recorded value,
|
getMin | back to summary |
---|---|
public final double getMin() Returns the minimum recorded value,
|
getSum | back to summary |
---|---|
public final double getSum() Returns the sum of values recorded, or zero if no values have been recorded. The value of a floating-point sum is a function both of the
input values as well as the order of addition operations. The
order of addition operations of this method is intentionally
not defined to allow for implementation flexibility to improve
the speed and accuracy of the computed result.
In particular, this method may be implemented using compensated
summation or other technique to reduce the error bound in the
numerical sum compared to a simple summation of Various conditions can result in a non-finite sum being computed. This can occur even if the all the recorded values being summed are finite. If any recorded value is non-finite, the sum will be non-finite:
API Note Values sorted by increasing absolute magnitude tend to yield more accurate results.
|
sumWithCompensation | back to summary |
---|---|
private void sumWithCompensation(double value) Incorporate a new double value using Kahan summation / compensated summation. |
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.
|