CKTIS / Java
DoubleSummaryStatistics — statistiche per valori double
DoubleSummaryStatistics raccoglie conteggio, somma, minimo, massimo e media di valori double. accept aggiunge un valore, mentre combine unisce le statistiche.
Versione: Java SE 21; repository runtime, production runtime not attested
Sintassi
DoubleSummaryStatistics stats = new DoubleSummaryStatistics();
stats.accept(value);
stats.combine(other);
stats.getCount();
stats.getSum();
stats.getMin();
stats.getMax();
stats.getAverage();java.util.DoubleSummaryStatistics è un accumulatore mutabile. accept(double) registra un valore; combine(other) unisce le statistiche nell’oggetto corrente.
getCount() restituisce long; getSum(), getMin(), getMax() e getAverage() restituiscono double. Un oggetto vuoto ha conteggio, somma e media pari a zero, minimo Double.POSITIVE_INFINITY e massimo Double.NEGATIVE_INFINITY.
NaN fa sì che minimo, massimo, somma e media siano NaN. Somma e media sono soggette a errori in virgola mobile; l’ordine della somma non è specificato.
L’oggetto non è thread-safe: non aggiornare contemporaneamente la stessa istanza senza sincronizzazione.
Esempi
import java.util.DoubleSummaryStatistics;
public class Main {
public static void main(String[] args) {
DoubleSummaryStatistics stats = new DoubleSummaryStatistics();
stats.accept(2.0);
stats.accept(4.0);
DoubleSummaryStatistics other = new DoubleSummaryStatistics();
other.accept(6.0);
stats.combine(other);
System.out.println("count=" + stats.getCount());
System.out.println("sum=" + stats.getSum());
System.out.println("min=" + stats.getMin());
System.out.println("max=" + stats.getMax());
System.out.println("average=" + stats.getAverage());
}
}Risultato
count=3 sum=12.0 min=2.0 max=6.0 average=4.0
Il codice mostrato e il risultato dichiarato sono stati verificati in un ambiente isolato con il metodo registrato nella prova di verifica di questa versione esatta.