DoubleSummaryStatistics - JRE Emulation | JRE Emulation
public class

DoubleSummaryStatistics

extends Object
implements DoubleConsumer
java.lang.Object
   ↳ java.util.DoubleSummaryStatistics

Class Overview

A state object for collecting statistics such as count, min, max, sum, and average.

This class is designed to work with (though does not require) {@linkplain java.util.stream 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 {@linkplain java.util.stream.Stream#collect(Collector) reduction} target for a {@linkplain java.util.stream.Stream 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.

Summary

Public Constructors
DoubleSummaryStatistics()
Construct an empty instance with zero count, zero sum, Double.POSITIVE_INFINITY min, Double.NEGATIVE_INFINITY max and zero average.
Public Methods
void accept(double value)
Records another value into the summary information.
void combine(DoubleSummaryStatistics other)
Combines the state of another DoubleSummaryStatistics into this one.
final double getAverage()
Returns the arithmetic mean of values recorded, or zero if no values have been recorded.
final long getCount()
Return the count of values recorded.
final double getMax()
Returns the maximum recorded value, Double.NaN if any recorded value was NaN or Double.NEGATIVE_INFINITY if no values were recorded.
final double getMin()
Returns the minimum recorded value, Double.NaN if any recorded value was NaN or Double.POSITIVE_INFINITY if no values were recorded.
final double getSum()
Returns the sum of values recorded, or zero if no values have been recorded.
String toString()
Returns a string containing a concise, human-readable description of this object. Returns a non-empty string representation of this object suitable for debugging.
Inherited Methods
[Expand]
From class java.lang.Object
From interface java.util.function.DoubleConsumer

Public Constructors

public DoubleSummaryStatistics ()

Construct an empty instance with zero count, zero sum, Double.POSITIVE_INFINITY min, Double.NEGATIVE_INFINITY max and zero average.

Public Methods

public void accept (double value)

Records another value into the summary information.

Parameters
value the input value

public void combine (DoubleSummaryStatistics other)

Combines the state of another DoubleSummaryStatistics into this one.

Parameters
other another DoubleSummaryStatistics
Throws
NullPointerException if other is null

public final double getAverage ()

Returns the arithmetic mean of values recorded, or zero if no values have been recorded. If any recorded value is a NaN or the sum is at any point a NaN then the average will be code NaN.

The average returned can vary depending upon the order in which values are recorded. This method may be implemented using compensated summation or other technique to reduce the error bound in the numerical sum used to compute the average.

Returns
  • the arithmetic mean of values, or zero if none

public final long getCount ()

Return the count of values recorded.

Returns
  • the count of values

public final double getMax ()

Returns the maximum recorded value, Double.NaN if any recorded value was NaN or Double.NEGATIVE_INFINITY if no values were recorded. Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero.

Returns
  • the maximum recorded value, Double.NaN if any recorded value was NaN or Double.NEGATIVE_INFINITY if no values were recorded

public final double getMin ()

Returns the minimum recorded value, Double.NaN if any recorded value was NaN or Double.POSITIVE_INFINITY if no values were recorded. Unlike the numerical comparison operators, this method considers negative zero to be strictly smaller than positive zero.

Returns
  • the minimum recorded value, Double.NaN if any recorded value was NaN or Double.POSITIVE_INFINITY if no values were recorded

public final double getSum ()

Returns the sum of values recorded, or zero if no values have been recorded. If any recorded value is a NaN or the sum is at any point a NaN then the sum will be NaN.

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 double values.

Returns
  • the sum of values, or zero if none

public String toString ()

Returns a string containing a concise, human-readable description of this object. Subclasses are encouraged to override this method and provide an implementation that takes into account the object's type and data. The default implementation is equivalent to the following expression:

   getClass().getName() + '@' + Integer.toHexString(hashCode())

See Writing a useful toString method if you intend implementing your own toString method. 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.

Returns
  • a printable representation of this object.