private void populateNextRate ( ) { final MutableDataPoint prev_data = new MutableDataPoint ( ) ; if ( source . hasNext ( ) ) { prev_data . reset ( next_data ) ; next_data . reset ( source . next ( ) ) ; final long t0 = prev_data . timestamp ( ) ; final long t1 = next_data . timestamp ( ) ; if ( t1 <= t0 ) { throw new IllegalStateException ( "Next timestamp (" + t1 + ") is supposed to be " + " strictly greater than the previous one (" + t0 + "), but it's" + " not. this=" + this ) ; } // TODO: for backwards compatibility we'll convert the ms to seconds // but in the future we should add a ratems flag that will calculate // the rate as is. final double time_delta_secs = ( ( double ) ( t1 - t0 ) / 1000.0 ) ; double difference ; if ( prev_data . isInteger ( ) && next_data . isInteger ( ) ) { // NOTE: Calculates in the long type to avoid precision loss // while converting long values to double values if both values are long. // NOTE: Ignores the integer overflow. difference = next_data . longValue ( ) - prev_data . longValue ( ) ; } else { difference = next_data . toDouble ( ) - prev_data . toDouble ( ) ; } if ( options . isCounter ( ) && difference < 0 ) { if ( options . getDropResets ( ) ) { populateNextRate ( ) ; return ; } if ( prev_data . isInteger ( ) && next_data . isInteger ( ) ) { // NOTE: Calculates in the long type to avoid precision loss // while converting long values to double values if both values are long. difference = options . getCounterMax ( ) - prev_data . longValue ( ) + next_data . longValue ( ) ; } else { difference = options . getCounterMax ( ) - prev_data . toDouble ( ) + next_data . toDouble ( ) ; } // If the rate is greater than the reset value, return a 0 final double rate = difference / time_delta_secs ; if ( options . getResetValue ( ) > RateOptions . DEFAULT_RESET_VALUE && rate > options . getResetValue ( ) ) { next_rate . reset ( next_data . timestamp ( ) , 0.0D ) ; } else { next_rate . reset ( next_data . timestamp ( ) , rate ) ; } } else { next_rate . reset ( next_data . timestamp ( ) , ( difference / time_delta_secs ) ) ; } } else { // Invalidates the next rate with invalid timestamp. next_rate . reset ( INVALID_TIMESTAMP , 0 ) ; } }
Populate the next rate .