@Test public void regenerateTokens() { final RateLimitedValue value = new RateLimitedValue( 0L, 2000D, 2000D ); value.setTokenCount( 0D ); assertEquals( value.getTokenCount(), 0D ); assertEquals( getLastRegenTime( value ), 0L ); value.regenerateTokens( 0L ); assertEquals( value.getTokenCount(), 0D ); assertEquals( getLastRegenTime( value ), 0L ); value.regenerateTokens( 50L ); assertEquals( value.getTokenCount(), 100D, 0.1 ); assertEquals( getLastRegenTime( value ), 50L ); }
void regenerateTokens( final long now ) { final long duration = now - _lastRegenTime; if ( duration > 0 ) { final double newTokenCount = _tokenCount + ( duration * _tokensPerSecond / MILLIS_PER_SECOND ); _tokenCount = Math.min( _maxTokenCount, newTokenCount ); _lastRegenTime = now; } }
RateLimitedValue { void regenerateTokens( final long now ) { final long duration = now - _lastRegenTime; if ( duration > 0 ) { final double newTokenCount = _tokenCount + ( duration * _tokensPerSecond / MILLIS_PER_SECOND ); _tokenCount = Math.min( _maxTokenCount, newTokenCount ); _lastRegenTime = now; } } }
RateLimitedValue { void regenerateTokens( final long now ) { final long duration = now - _lastRegenTime; if ( duration > 0 ) { final double newTokenCount = _tokenCount + ( duration * _tokensPerSecond / MILLIS_PER_SECOND ); _tokenCount = Math.min( _maxTokenCount, newTokenCount ); _lastRegenTime = now; } } RateLimitedValue( final long now, final double tokensPerSecond, final double maxTokenAmount ); }
RateLimitedValue { void regenerateTokens( final long now ) { final long duration = now - _lastRegenTime; if ( duration > 0 ) { final double newTokenCount = _tokenCount + ( duration * _tokensPerSecond / MILLIS_PER_SECOND ); _tokenCount = Math.min( _maxTokenCount, newTokenCount ); _lastRegenTime = now; } } RateLimitedValue( final long now, final double tokensPerSecond, final double maxTokenAmount );  }
RateLimitedValue { void regenerateTokens( final long now ) { final long duration = now - _lastRegenTime; if ( duration > 0 ) { final double newTokenCount = _tokenCount + ( duration * _tokensPerSecond / MILLIS_PER_SECOND ); _tokenCount = Math.min( _maxTokenCount, newTokenCount ); _lastRegenTime = now; } } RateLimitedValue( final long now, final double tokensPerSecond, final double maxTokenAmount );   }