Package one.microstream.math
Class Countdown
java.lang.Object
one.microstream.math.Countdown
public class Countdown extends Object
Class that wraps a combination of start value and remaining value to implement a countdown.
The countdown can be decremented, resetted and be checked for having expired or still being active.
The countdown can be decremented, resetted and be checked for having expired or still being active.
-
Constructor Summary
Constructors Constructor Description Countdown(int startValue)Instantiates a new countdown with a given start value. -
Method Summary
Modifier and Type Method Description intdecrease(int offset)intdecrement()Decrements this countdown by 1.intexpire()Immediately expires this countdown.intgetRemainingValue()intgetStartValue()booleanisActive()Tells if this countdown is still active (meaning its remaining value is greater than 0)booleanisAtStart()Tells if this countdown is still full (meaning its remaining value is equal to its start value)booleanisExpired()Tells if this countdown is expired(meaning its remaining value is 0)intreset()Resets this countdown to its start value.StringtoString()
-
Constructor Details
-
Countdown
public Countdown(int startValue)Instantiates a new countdown with a given start value.- Parameters:
startValue- may not be negative
-
-
Method Details
-
getStartValue
public int getStartValue()- Returns:
- the start value of this countdown. Cannot be negative.
-
getRemainingValue
public int getRemainingValue()- Returns:
- the remaining value of this countdown. Will always be in the range [0;startValue]
-
toString
-
decrement
public int decrement()Decrements this countdown by 1.- Returns:
- 1 if the countdown already expired, 0 otherwise (returns the unconsumed amount of value 1)
- See Also:
decrease(int)
-
decrease
public int decrease(int offset)- Returns:
- the unconsumed amount of
offsetdue to preterm expiration of the countdown. - See Also:
decrement()
-
reset
public int reset()Resets this countdown to its start value.- Returns:
- the remaining countdown value before the reset.
-
expire
public int expire()Immediately expires this countdown.- Returns:
- the remaining countdown value before the expiration.
-
isActive
public boolean isActive()Tells if this countdown is still active (meaning its remaining value is greater than 0)- Returns:
trueif this countdown's remaining value is greater 0, false otherwise.- See Also:
isAtStart(),isExpired()
-
isExpired
public boolean isExpired()Tells if this countdown is expired(meaning its remaining value is 0)- Returns:
trueif this countdown's remaining value 0, false otherwise.- See Also:
isActive(),isAtStart()
-
isAtStart
public boolean isAtStart()Tells if this countdown is still full (meaning its remaining value is equal to its start value)- Returns:
trueif this countdown's remaining value is the same as its start value, false otherwise.- See Also:
isActive(),isExpired()
-