Added in API level 24

LongSummaryStatistics

open class LongSummaryStatistics : IntConsumer, LongConsumer
kotlin.Any
   ↳ java.util.LongSummaryStatistics

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) streams. For example, you can compute summary statistics on a stream of longs with:

<code>LongSummaryStatistics stats = longStream.collect(LongSummaryStatistics::new,
                                                   LongSummaryStatistics::accept,
                                                   LongSummaryStatistics::combine);
  </code>

LongSummaryStatistics can be used as a reduction target for a stream. For example:

<code>LongSummaryStatistics stats = people.stream()
                                      .collect(Collectors.summarizingLong(Person::getAge));
 </code>
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

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

LongSummaryStatistics(count: Long, min: Long, max: Long, sum: Long)

Constructs a non-empty instance with the specified count, min, max, and sum.

Public methods
open Unit
accept(value: Int)

Records a new int value into the summary information.

open Unit
accept(value: Long)

Records a new long value into the summary information.

open Unit

Combines the state of another LongSummaryStatistics into this one.

Double

Returns the arithmetic mean of values recorded, or zero if no values have been recorded.

Long

Returns the count of values recorded.

Long

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

Long

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

Long

Returns the sum of values recorded, or zero if no values have been recorded.

open String

Returns a non-empty string representation of this object suitable for debugging.

Inherited functions

Public constructors

LongSummaryStatistics

Added in API level 24
LongSummaryStatistics()

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

LongSummaryStatistics

Added in API level 33
LongSummaryStatistics(
    count: Long,
    min: Long,
    max: Long,
    sum: Long)

Constructs a non-empty instance with the specified count, min, max, and sum.

If count is zero then the remaining arguments are ignored and an empty instance is constructed.

If the arguments are inconsistent then an IllegalArgumentException is thrown. The necessary consistent argument conditions are:

  • count >= 0
  • min <= max
Parameters
count Long: the count of values
min Long: the minimum value
max Long: the maximum value
sum Long: the sum of all values
Exceptions
java.lang.IllegalArgumentException if the arguments are inconsistent

Public methods

accept

Added in API level 24
open fun accept(value: Int): Unit

Records a new int value into the summary information.

Parameters
value Int: the input value

accept

Added in API level 24
open fun accept(value: Long): Unit

Records a new long value into the summary information.

Parameters
value Long: the input value

combine

Added in API level 24
open fun combine(other: LongSummaryStatistics!): Unit

Combines the state of another LongSummaryStatistics into this one.

Parameters
other LongSummaryStatistics!: another LongSummaryStatistics
Exceptions
java.lang.NullPointerException if other is null

getAverage

Added in API level 24
fun getAverage(): Double

Returns the arithmetic mean of values recorded, or zero if no values have been recorded.

Return
Double The arithmetic mean of values, or zero if none

getCount

Added in API level 24
fun getCount(): Long

Returns the count of values recorded.

Return
Long the count of values

getMax

Added in API level 24
fun getMax(): Long

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

Return
Long the maximum value, or Long.MIN_VALUE if none

getMin

Added in API level 24
fun getMin(): Long

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

Return
Long the minimum value, or Long.MAX_VALUE if none

getSum

Added in API level 24
fun getSum(): Long

Returns the sum of values recorded, or zero if no values have been recorded.

Return
Long the sum of values, or zero if none

toString

Added in API level 24
open fun toString(): String

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.

Return
String a string representation of the object.