LongSummaryStatistics

public class LongSummaryStatistics extends Object
implements LongConsumer IntConsumer

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 longs with:

 LongSummaryStatistics stats = longStream.collect(LongSummaryStatistics::new,
                                                  LongSummaryStatistics::accept,
                                                  LongSummaryStatistics::combine);
 

LongSummaryStatistics can be used as a {@linkplain java.util.stream.Stream#collect(Collector)} reduction} target for a {@linkplain java.util.stream.Stream 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.

Public Constructor Summary

LongSummaryStatistics()
Construct an empty instance with zero count, zero sum, Long.MAX_VALUE min, Long.MIN_VALUE max and zero average.

Public Method Summary

void
accept(int value)
Records a new int value into the summary information.
void
accept(long value)
Records a new long value into the summary information.
void
combine(LongSummaryStatistics other)
Combines the state of another LongSummaryStatistics into this one.
final double
getAverage()
Returns the arithmetic mean of values recorded, or zero if no values have been recorded.
final long
getCount()
Returns the count of values recorded.
final long
getMax()
Returns the maximum value recorded, or Long.MIN_VALUE if no values have been recorded
final long
getMin()
Returns the minimum value recorded, or Long.MAX_VALUE if no values have been recorded.
final long
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.

Inherited Method Summary

Public Constructors

public LongSummaryStatistics ()

Construct an empty instance with zero count, zero sum, Long.MAX_VALUE min, Long.MIN_VALUE max and zero average.

Public Methods

public void accept (int value)

Records a new int value into the summary information.

Parameters
value the input value

public void accept (long value)

Records a new long value into the summary information.

Parameters
value the input value

public void combine (LongSummaryStatistics other)

Combines the state of another LongSummaryStatistics into this one.

Parameters
other another LongSummaryStatistics
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.

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

public final long getCount ()

Returns the count of values recorded.

Returns
  • the count of values

public final long getMax ()

Returns the maximum value recorded, or Long.MIN_VALUE if no values have been recorded

Returns
  • the maximum value, or Long.MIN_VALUE if none

public final long getMin ()

Returns the minimum value recorded, or Long.MAX_VALUE if no values have been recorded.

Returns
  • the minimum value, or Long.MAX_VALUE if none

public final long getSum ()

Returns the sum of values