com.metamatrix.core.util
Class Stopwatch

java.lang.Object
  extended by com.metamatrix.core.util.Stopwatch
All Implemented Interfaces:
java.io.Serializable

public class Stopwatch
extends java.lang.Object
implements java.io.Serializable

See Also:
Serialized Form

Nested Class Summary
 class Stopwatch.Statistics
           
 
Constructor Summary
Stopwatch()
           
 
Method Summary
 float getAverageDuration()
          Return the average duration recorded as a date.
 int getSegmentCount()
          Return the number of segments that have been recorded.
 java.lang.String getTimeValueAsString(float value)
           
 java.lang.String getTimeValueAsString(long value)
           
 long getTotalDuration()
          Return the total duration recorded, in milliseconds.
 java.lang.String getValueAsString(int value)
           
 boolean isActive()
          Return whether the stopwatch is active.
static void logTimedMessage(java.lang.String message, long time, Logger log)
          Logs a message containing a time increment in milliseconds and a messages describing the operation or context that the time relates to.
 void printStatistics()
          Print the current statistics to System.out
 void printStatistics(java.io.PrintStream stream)
          Print the current statistics
 void reset()
          Reset the statistics for this stopwatch, regardless of the active state.
 void setActive()
          Set the stopwatch as active.
 void setInactive()
          Set the stopwatch as inactive.
 void start()
          If the stopwatch is active, record the starting time for a time segment.
 void start(boolean reset)
          If the stopwatch is active, record the starting time for a time segment.
 void stop()
          If the stopwatch is active, record the ending time for a time segment.
 void stopLogIncrementAndRestart(java.lang.String message, Logger log)
          This convience method stops the current stopwatch, logs a message containing the resulting time increment/duration and restarts the stopwatch.
 void stopPrintIncrementAndRestart(java.lang.String message)
          This convience method stops the current stopwatch, prints a message to System.out containing the resulting time increment/duration and restarts the stopwatch.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Stopwatch

public Stopwatch()
Method Detail

isActive

public boolean isActive()
Return whether the stopwatch is active. When the stopwatch is active, it is recording the time durations (via start and stop) and will print duration statistics (via printDuration). When the stopwatch is inactive, invoking these methods does nothing but return immediately.

Returns:
true if the stopwatch is active, or false if it is inactive.

setInactive

public void setInactive()
Set the stopwatch as inactive.

See Also:
isActive

setActive

public void setActive()
Set the stopwatch as active.

See Also:
isActive

start

public void start()
If the stopwatch is active, record the starting time for a time segment. If the stopwatch is inactive, the method returns immediately.

See Also:
isActive

start

public void start(boolean reset)
If the stopwatch is active, record the starting time for a time segment. If the stopwatch is inactive, the method returns immediately.

See Also:
isActive

stop

public void stop()
If the stopwatch is active, record the ending time for a time segment. If the stopwatch is inactive, the method returns immediately.

See Also:
isActive

reset

public void reset()
Reset the statistics for this stopwatch, regardless of the active state.


getTotalDuration

public long getTotalDuration()
Return the total duration recorded, in milliseconds.

Returns:
the total number of milliseconds that have been recorded

getAverageDuration

public float getAverageDuration()
Return the average duration recorded as a date.

Returns:
the number of milliseconds that have been recorded averaged over the number of segments

getSegmentCount

public int getSegmentCount()
Return the number of segments that have been recorded.

Returns:
the number of segments

toString

public java.lang.String toString()
Overrides:
toString in class java.lang.Object

getTimeValueAsString

public java.lang.String getTimeValueAsString(long value)

getTimeValueAsString

public java.lang.String getTimeValueAsString(float value)

getValueAsString

public java.lang.String getValueAsString(int value)

printStatistics

public void printStatistics(java.io.PrintStream stream)
Print the current statistics

Parameters:
stream - the stream to which the statistics should be printed

printStatistics

public void printStatistics()
Print the current statistics to System.out


logTimedMessage

public static void logTimedMessage(java.lang.String message,
                                   long time,
                                   Logger log)
Logs a message containing a time increment in milliseconds and a messages describing the operation or context that the time relates to.

Parameters:
message -
time -
Since:
4.3

stopLogIncrementAndRestart

public void stopLogIncrementAndRestart(java.lang.String message,
                                       Logger log)
This convience method stops the current stopwatch, logs a message containing the resulting time increment/duration and restarts the stopwatch.

Parameters:
message -
Since:
4.3

stopPrintIncrementAndRestart

public void stopPrintIncrementAndRestart(java.lang.String message)
This convience method stops the current stopwatch, prints a message to System.out containing the resulting time increment/duration and restarts the stopwatch.

Parameters:
message -
Since:
4.3


Copyright © 2009. All Rights Reserved.