LongSummaryStatistics - JRE Emulation | JRE Emulation
public class

LongSummaryStatistics

extends Object
implements LongConsumer IntConsumer
java.lang.Object
   ↳ java.util.LongSummaryStatistics

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

Summary

Public Constructors
LongSummaryStatistics()
Construct an empty instance with zero count, zero sum, Long.MAX_VALUE min, Long.MIN_VALUE max and zero average.
Public Methods
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 Methods
[Expand]
From class java.lang.Object
From interface java.util.function.LongConsumer
From interface java.util.function.IntConsumer

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 recorded, or zero if no values have been recorded.

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 printable representation of this object.