Package com.day.util

Class Timing


  • public class Timing
    extends java.lang.Object
    The Timing class supports timing code fragments. A timer has a name, which may be used for informational purposes, and a start time against which the elapsed time is calculated.

    The start time is first set to the time of instance creation and may later be set to the current time using the reset() method. The name of the timer is also set at instance creation time and may be changed using the setName(java.lang.String) method.

    The time elapsed since the last timer reset (either instance creation or call to the reset() method) is accessible through the getElapsed() and may be logged using the stamp(java.lang.String) method.

    Since:
    gumbaer
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static java.lang.String DEFAULT_NAME
      The defualt name for instances
    • Constructor Summary

      Constructors 
      Constructor Description
      Timing()
      Creates an instance with the default name.
      Timing​(java.lang.String name)
      Creates an instance with the given name.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      long getElapsed()
      Returns the time in milliseconds elapsed since the starting time.
      java.lang.String getName()
      Returns the name of this instance.
      long getStartTime()
      Returns the starting time of this instance.
      void reset()
      Resets the starting time of this instance to the current system time.
      void setName​(java.lang.String name)
      Sets the name of this instance.
      void stamp​(java.lang.String message)
      Writes the elapsed time to the timer log.
      java.lang.String toString()
      Returns a string representation of this instance, which consists of the name and human readable form of the start time.
      • Methods inherited from class java.lang.Object

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

      • DEFAULT_NAME

        public static final java.lang.String DEFAULT_NAME
        The defualt name for instances
        See Also:
        Constant Field Values
    • Constructor Detail

      • Timing

        public Timing()
        Creates an instance with the default name. The start time of the new instance is set to the time of instance creation.

        Calling this method is equivalent to calling new Timing(null)

        See Also:
        DEFAULT_NAME
      • Timing

        public Timing​(java.lang.String name)
        Creates an instance with the given name. The start time of the new instance is set to the time of instance creation.
        Parameters:
        name - The name of the new instance. If the name is empty or null, the name will be set to the default name.
    • Method Detail

      • getName

        public java.lang.String getName()
        Returns the name of this instance.
        Returns:
        The name of this instance.
      • setName

        public void setName​(java.lang.String name)
        Sets the name of this instance.
        Parameters:
        name - The new name to set on this instance. If the name is empty or null, the name will be set to the default name.
      • getStartTime

        public long getStartTime()
        Returns the starting time of this instance.
        Returns:
        the start time
        See Also:
        reset()
      • reset

        public void reset()
        Resets the starting time of this instance to the current system time.
        See Also:
        getStartTime()
      • getElapsed

        public long getElapsed()
        Returns the time in milliseconds elapsed since the starting time.
        Returns:
        the elapsed time
        See Also:
        reset(), getStartTime()
      • stamp

        public void stamp​(java.lang.String message)
        Writes the elapsed time to the timer log. The message contains the timer name, the supplied message and the elapsed time in milliseconds.

        The log message is logged as an informational message at level INFO to the logger misc.timing.

        Parameters:
        message - The message to be added to the log message.
      • toString

        public java.lang.String toString()
        Returns a string representation of this instance, which consists of the name and human readable form of the start time.
        Overrides:
        toString in class java.lang.Object
        Returns:
        A string represenation of this instance.