java.lang.Object
com.github.cowwoc.tokenbucket.Limit.Builder
- Enclosing class:
 - Limit
 
Builds a Limit.
- 
Method Summary
Modifier and TypeMethodDescriptionbuild()Builds a new Limit.longReturns the initial number of tokens in the bucket.initialTokens(long initialTokens) Sets the initial number of tokens in the bucket.longReturns the maximum number of tokens that the bucket may hold before overflowing.maximumTokens(long maximumTokens) Sets the maximum number of tokens that the bucket may hold before overflowing.period()Indicates how oftentokensPerPeriodshould be added to the bucket.Indicates how oftentokensPerPeriodshould be added to the bucket.longReturns the number of tokens that are refilled at a time.refillSize(long refillSize) Sets the number of tokens that are refilled at a time.longReturns the number of tokens to add to the bucket everyperiod.tokensPerPeriod(long tokensPerPeriod) Sets the number of tokens to add to the bucket everyperiod.toString()userData()Returns user data associated with this limit.Sets user data associated with this limit. 
- 
Method Details
- 
tokensPerPeriod
public long tokensPerPeriod()Returns the number of tokens to add to the bucket everyperiod. The default is1.- Returns:
 - the number of tokens to add to the bucket every 
period 
 - 
tokensPerPeriod
Sets the number of tokens to add to the bucket everyperiod.- Parameters:
 tokensPerPeriod- the number of tokens to add to the bucket everyperiod- Returns:
 - this
 - Throws:
 IllegalArgumentException- iftokensPerPeriodis negative or zero
 - 
period
Indicates how oftentokensPerPeriodshould be added to the bucket. The default is1 second.- Returns:
 - how often 
tokensPerPeriodshould be added to the bucket 
 - 
period
Indicates how oftentokensPerPeriodshould be added to the bucket.- Parameters:
 period- indicates how oftentokensPerPeriodshould be added to the bucket- Returns:
 - this
 - Throws:
 IllegalArgumentException- ifperiodis negative or zeroNullPointerException- ifperiodis null
 - 
initialTokens
public long initialTokens()Returns the initial number of tokens in the bucket. The value may be negative, in which case the bucket must accumulate a positive number of tokens before they may be consumed. The default is0.- Returns:
 - the number amount of tokens in the bucket
 
 - 
initialTokens
Sets the initial number of tokens in the bucket. The value may be negative, in which case the bucket must accumulate a positive number of tokens before they may be consumed.- Parameters:
 initialTokens- the initial number of tokens in the bucket- Returns:
 - this
 
 - 
maximumTokens
public long maximumTokens()Returns the maximum number of tokens that the bucket may hold before overflowing. The default isLong.MAX_VALUE.- Returns:
 - the maximum number of tokens that the bucket may hold before overflowing (subsequent tokens are discarded)
 
 - 
maximumTokens
Sets the maximum number of tokens that the bucket may hold before overflowing.- Parameters:
 maximumTokens- the maximum number of tokens that the bucket may hold before overflowing (subsequent tokens are discarded)- Returns:
 - this
 - Throws:
 IllegalArgumentException- ifmaximumTokensis negative or zero
 - 
refillSize
public long refillSize()Returns the number of tokens that are refilled at a time.At one end of the spectrum, one may refill tokens one at a time during the
period. On the other spectrum, one may refilltokensPerPeriodtokens once perperiod.NOTE: When completing a
perioda smaller number of tokens may be refilled in order to avoid surpassingtokensPerPerioddue to rounding errors.The default is
1.- Returns:
 - the minimum number of tokens by which the limit may be refilled
 
 - 
refillSize
Sets the number of tokens that are refilled at a time.At one end of the spectrum, one may refill tokens one at a time during the
period. On the other spectrum, one may refilltokensPerPeriodtokens once perperiod.NOTE: When completing a
perioda smaller number of tokens may be refilled in order to avoid surpassingtokensPerPerioddue to rounding errors.- Parameters:
 refillSize- the minimum number of tokens by which the limit may be refilled- Returns:
 - this
 - Throws:
 IllegalArgumentException- ifrefillSizeis negative or zero
 - 
userData
Returns user data associated with this limit. The default isnull.- Returns:
 - the data associated with this limit
 
 - 
userData
Sets user data associated with this limit.- Parameters:
 userData- the data associated with this limit- Returns:
 - this
 
 - 
build
Builds a new Limit.- Returns:
 - a new Limit
 
 - 
toString
 
 -