public void computeStats ( ) { if ( statsComputed . getAndSet ( true ) ) { return ; } if ( curSize == 0 ) { return ; } Arrays . sort ( values , 0 , curSize ) ; // to compute percentileValues min = values [ 0 ] ; max = values [ curSize - 1 ] ; total = 0L ; double sumSquares = 0.0 ; for ( int i = 0 ; i < curSize ; ++ i ) { total += values [ i ] ; sumSquares += values [ i ] * values [ i ] ; } mean = ( double ) total / curSize ; if ( curSize == 1 ) { variance = 0d ; } else { variance = ( sumSquares - ( ( double ) total * total / curSize ) ) / ( curSize - 1 ) ; } stddev = Math . sqrt ( variance ) ; computePercentiles ( curSize ) ; }
Compute stats for the current set of values .