Class Timer


  • public final class Timer
    extends java.lang.Object
    Simple timer class.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      private boolean isRunning  
      private long start  
      private long time  
    • Constructor Summary

      Constructors 
      Constructor Description
      Timer()
      Create a new timer.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getTime()
      Get the currently accumulated time.
      TimeSpan getTimeSpan()
      Get the accumulated time as a time span object.
      boolean reset()
      Reset the timer to 0.
      boolean start()
      (Re)start the timer.
      boolean stop()
      Stop the timer.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • time

        private long time
      • start

        private long start
      • isRunning

        private boolean isRunning
    • Constructor Detail

      • Timer

        public Timer()
        Create a new timer. The new timer will NOT be started automatically. You need to invoke start() explicitly.
    • Method Detail

      • start

        public boolean start()
        (Re)start the timer. If the timer has already been started, does nothing.
        Returns:
        false iff the timer is already running.
      • stop

        public boolean stop()
        Stop the timer.
        Returns:
        false iff the timer is not running.
      • reset

        public boolean reset()
        Reset the timer to 0. The timer must be stopped before it can be reset.
        Returns:
        false iff the timer is currently running.
      • getTime

        public long getTime()
        Get the currently accumulated time. This method may be called while the timer is running, or after it has been stopped.
        Returns:
        The duration in milliseconds.
      • getTimeSpan

        public TimeSpan getTimeSpan()
        Get the accumulated time as a time span object.
        Returns:
        A time span object for the current value of the timer.
        See Also:
        getTime()