Class 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.
    • Constructor Summary

      Constructors 
      Constructor Description
      Countdown​(int startValue)
      Instantiates a new countdown with a given start value.
    • Constructor Detail

      • Countdown

        public Countdown​(int startValue)
        Instantiates a new countdown with a given start value.
        Parameters:
        startValue - may not be negative
    • Method Detail

      • 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

        public String toString()
        Overrides:
        toString in class Object
        Returns:
        a String representing the plain remaining value of this countdown.
      • 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 offset due 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:
        true if 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:
        true if 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:
        true if this countdown's remaining value is the same as its start value, false otherwise.
        See Also:
        isActive(), isExpired()