Class TimeMeasure


  • public class TimeMeasure
    extends java.lang.Object
    Utility class for time measurements. Instances may be reset for reuse.
    • Constructor Summary

      Constructors 
      Constructor Description
      TimeMeasure()
      Create a new instance, used a formatter converting everything >= 5000 ms to seconds (X.Y -> 6.1).
      TimeMeasure​(TimeMeasure.ITimeMeasureFormat _formatter)
      Create a new instance using _ts millis as
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getElapsed()
      Returns the elapsed time in milliseconds.
      long getElapsedAndReset()  
      java.lang.String getElapsedFormatted​(java.text.DateFormat _dateFormat)
      Formats the elapsed time using the given dateFormatter.
      (package private) java.lang.String getElapsedFormatted​(java.text.DateFormat _dateFormat, long _elapsedTime)
      Same as above, used for proper unit testing.
      long getElapsedSeconds()
      Returns the elapsed time in seconds.
      long getStartTime()
      Returns the start time in milliseconds.
      TimeMeasure reset()
      Resets the start time.
      (package private) void setStartTm​(long _tm)
      Change the start time (for unit testing only!).
      java.lang.String toString()
      Returns the elapsed time in milliseconds formatted as string.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • TimeMeasure

        public TimeMeasure​(TimeMeasure.ITimeMeasureFormat _formatter)
        Create a new instance using _ts millis as
        Parameters:
        _formatter - formatter to use for toString() call
      • TimeMeasure

        public TimeMeasure()
        Create a new instance, used a formatter converting everything >= 5000 ms to seconds (X.Y -> 6.1).
    • Method Detail

      • reset

        public final TimeMeasure reset()
        Resets the start time.
        Returns:
        the object
      • getStartTime

        public long getStartTime()
        Returns the start time in milliseconds.
        Returns:
        start time in ms
      • getElapsed

        public long getElapsed()
        Returns the elapsed time in milliseconds.
        Returns:
        elapsed time in ms
      • getElapsedSeconds

        public long getElapsedSeconds()
        Returns the elapsed time in seconds.
        Returns:
        elapsed time in seconds
      • getElapsedFormatted

        public java.lang.String getElapsedFormatted​(java.text.DateFormat _dateFormat)
        Formats the elapsed time using the given dateFormatter. If null is given, a new Formatter with format HH:mm:ss.SSS will be used. The timezone of the given dateFormatter will always be set to 'UTC' to avoid any timezone related offsets.
        Parameters:
        _dateFormat - date format
        Returns:
        formatted string
      • getElapsedFormatted

        java.lang.String getElapsedFormatted​(java.text.DateFormat _dateFormat,
                                             long _elapsedTime)
        Same as above, used for proper unit testing.
        Parameters:
        _dateFormat -
        _elapsedTime -
        Returns:
        formatted string
      • setStartTm

        void setStartTm​(long _tm)
        Change the start time (for unit testing only!).
        Parameters:
        _tm -
      • getElapsedAndReset

        public long getElapsedAndReset()
      • toString

        public java.lang.String toString()
        Returns the elapsed time in milliseconds formatted as string.
        Overrides:
        toString in class java.lang.Object
        Returns:
        elapsed time in ms