Class StopWatch

  • All Implemented Interfaces:
    java.io.Serializable, java.lang.Cloneable
    Direct Known Subclasses:
    StopWatch.Wrapper

    public class StopWatch
    extends java.lang.Object
    implements java.io.Serializable, java.lang.Cloneable
    Simulates a stop watch with a lap counter.
    Version:
    $Revision$
    See Also:
    Serialized Form
    • Nested Class Summary

      Nested Classes 
      Modifier and Type Class Description
      private static class  StopWatch.Wrapper
      Base wrapper class for other wrappers.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int count
      The lap count
      protected boolean running
      Is the watch started
      private static long serialVersionUID
      The serialVersionUID
      protected long start
      Start time
      protected long stop
      Stop time
      protected long total
      Total time
    • Constructor Summary

      Constructors 
      Constructor Description
      StopWatch()
      Default constructor.
      StopWatch​(boolean running)
      Construct a StopWatch.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      java.lang.Object clone()
      Return a cloned copy of this object.
      private void formatElapsedTime​(java.lang.StringBuffer buff, long lapsed)  
      long getAverageLapTime()
      Get the average lap time since the watch was started.
      int getLapCount()
      Get the lap count.
      long getLapTime()
      Get the elapsed lap time since the watch was started.
      long getTime()
      Get the elapsed time since the watch was created or last reset.
      boolean isRunning()
      Check if the watch is running.
      static StopWatch makeSynchronized​(StopWatch watch)
      Return a synchronized stop watch.
      void reset()
      Reset the watch.
      void start()
      Start the watch.
      void start​(boolean reset)
      Start the watch.
      long stop()
      Stop the watch.
      java.lang.String toString()
      Return a string representation.
      • Methods inherited from class java.lang.Object

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

      • serialVersionUID

        private static final long serialVersionUID
        The serialVersionUID
        See Also:
        Constant Field Values
      • total

        protected long total
        Total time
      • start

        protected long start
        Start time
      • stop

        protected long stop
        Stop time
      • count

        protected int count
        The lap count
      • running

        protected boolean running
        Is the watch started
    • Constructor Detail

      • StopWatch

        public StopWatch()
        Default constructor.
      • StopWatch

        public StopWatch​(boolean running)
        Construct a StopWatch.
        Parameters:
        running - Start the watch
    • Method Detail

      • start

        public void start​(boolean reset)
        Start the watch.
        Parameters:
        reset - True to reset the watch prior to starting.
      • start

        public void start()
        Start the watch.
      • stop

        public long stop()
        Stop the watch.
        Returns:
        Elapsed time or 0 if the watch was never started.
      • reset

        public void reset()
        Reset the watch.
      • getLapCount

        public int getLapCount()
        Get the lap count.
        Returns:
        The lap count.
      • getLapTime

        public long getLapTime()
        Get the elapsed lap time since the watch was started.
        Returns:
        Elapsed lap time or 0 if the watch was never started
      • getAverageLapTime

        public long getAverageLapTime()
        Get the average lap time since the watch was started.
        Returns:
        Average lap time since the watch was started.
      • getTime

        public long getTime()
        Get the elapsed time since the watch was created or last reset.
        Returns:
        Elapsed time or 0 if the watch was never started.
      • isRunning

        public boolean isRunning()
        Check if the watch is running.
        Returns:
        True if the watch is running.
      • toString

        public java.lang.String toString()
        Return a string representation.
        Overrides:
        toString in class java.lang.Object
      • formatElapsedTime

        private void formatElapsedTime​(java.lang.StringBuffer buff,
                                       long lapsed)
      • clone

        public java.lang.Object clone()
        Return a cloned copy of this object.
        Overrides:
        clone in class java.lang.Object
        Returns:
        A cloned copy of this object.
      • makeSynchronized

        public static StopWatch makeSynchronized​(StopWatch watch)
        Return a synchronized stop watch.
        Parameters:
        watch - StopWatch to synchronize.
        Returns:
        Synchronized stop watch.