Package com.day.util

Class Timing

java.lang.Object
com.day.util.Timing

public class Timing extends 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 final String
    The defualt name for instances
  • Constructor Summary

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

    Modifier and Type
    Method
    Description
    long
    Returns the time in milliseconds elapsed since the starting time.
    Returns the name of this instance.
    long
    Returns the starting time of this instance.
    void
    Resets the starting time of this instance to the current system time.
    void
    Sets the name of this instance.
    void
    stamp(String message)
    Writes the elapsed time to the timer log.
    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 Details

  • Constructor Details

    • 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:
    • Timing

      public Timing(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 Details

    • getName

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

      public void setName(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

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

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

      public void stamp(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 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 Object
      Returns:
      A string represenation of this instance.