Class CTimer


  • public final class CTimer
    extends Object
    Simple utility to execute repeatedly calls a Runnable with a fixed time delay between each call.
    Author:
    Andrea "Stock" Stocchero
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      static class  CTimer.Status
      Enumerates the possible status of the timer.
    • Constructor Summary

      Constructors 
      Constructor Description
      CTimer​(Runnable task, int interval)
      Creates the timer with a Runnable to be executed repeatedly and the time, in milliseconds (thousands of a second), the timer should delay in between executions of the task.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      int getInterval()
      Returns the time, in milliseconds (thousands of a second), the timer should delay in between executions of the specified task.
      CTimer.Status getStatus()
      Returns the status of the timer.
      void start()
      Starts the timer which executes repeatedly calls.
      void start​(int interval)
      Starts the timer which executes repeatedly calls, setting the time, in milliseconds (thousands of a second), the timer should delay in between executions of the specified task.
      The time will override the previous interval time.
      void stop()
      Stops the timer which is currently running.
    • Constructor Detail

      • CTimer

        public CTimer​(Runnable task,
                      int interval)
        Creates the timer with a Runnable to be executed repeatedly and the time, in milliseconds (thousands of a second), the timer should delay in between executions of the task.
        Parameters:
        task - the task to be executed repeatedly
        interval - the time, in milliseconds (thousands of a second), the timer should delay in between executions of the specified task.
        Must be greater than 0.
    • Method Detail

      • getInterval

        public int getInterval()
        Returns the time, in milliseconds (thousands of a second), the timer should delay in between executions of the specified task.
        Returns:
        the time, in milliseconds (thousands of a second), the timer should delay in between executions of the specified task
      • getStatus

        public CTimer.Status getStatus()
        Returns the status of the timer.
        Returns:
        the status of the timer
      • start

        public void start​(int interval)
        Starts the timer which executes repeatedly calls, setting the time, in milliseconds (thousands of a second), the timer should delay in between executions of the specified task.
        The time will override the previous interval time.
        Parameters:
        interval - the time, in milliseconds (thousands of a second), the timer should delay in between executions of the specified task.
        Must be greater than 0.
      • start

        public void start()
        Starts the timer which executes repeatedly calls.
      • stop

        public void stop()
        Stops the timer which is currently running.