public synchronized void insert ( long data ) { resetIfNeeded ( ) ; long index = 0 ; if ( data >= this . upperBound ) { index = nBuckets - 1 ; } else if ( data < 0 ) { logger . error ( data + " can't be bucketed because it is negative!" ) ; return ; } else { index = data / step ; } if ( index < 0 || index >= nBuckets ) { // This should be dead code. Defending against code changes in // future. logger . error ( data + " can't be bucketed because index is not in range [0,nBuckets)." ) ; return ; } buckets [ ( int ) index ] ++ ; sum += data ; size ++ ; }
Insert a value into the right bucket of the histogram . If the value is larger than any bound insert into the last bucket . If the value is less than zero then ignore it .