de.rwth.utils
Class Stopwatch

java.lang.Object
  |
  +--de.rwth.utils.Stopwatch

public class Stopwatch
extends java.lang.Object

This class implements a stop watch which measures the elapsed time in milliseconds.

Version:
$Id: Stopwatch.java,v 1.3 2002/09/17 06:53:53 mohnen Exp $
Author:
Markus Mohnen

Field Summary
protected  java.lang.String desc
          The descriptive text of this stopwatch.
protected  long splitStartMillis
          The time where the last split was started (in milliseconds).
protected  boolean started
          true iff the stop watch was started more often than stopped.
protected  long startMillis
          The time where the stop watch was started (in milliseconds).
protected  java.util.Vector timings
          The accumulated timings.
 
Constructor Summary
Stopwatch()
          Creates a new stop watch w/o descriptive text.
Stopwatch(java.lang.String desc)
          Creates a new stop watch with descriptive text.
 
Method Summary
 java.util.Vector get()
          Returns the accumulated result after the watch was stopped.
 java.lang.String getDescription()
          Returns the descriptive text used when creating the stop watch plus.
static void main(java.lang.String[] args)
          Mini test environment.
 void reset()
           
 void reset(java.lang.String desc)
          Resets this stopwatch to its initial state.
 void split()
          Starts a new segment in the stopped time w/o descriptive text.
 void split(java.lang.String s)
          Starts a new segment in the stopped time with descriptive text.
 void start()
          Starts the stop watch w/o a start text.
 void start(java.lang.String s)
          Starts the stop watch with a start text.
 void stop()
          Stops the stop watch and returns the accumulated result.
 void stop(java.lang.String s)
          Stops the stop watch and returns the accumulated result.
 java.lang.String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

timings

protected java.util.Vector timings
The accumulated timings.

desc

protected java.lang.String desc
The descriptive text of this stopwatch.

startMillis

protected long startMillis
The time where the stop watch was started (in milliseconds). -1 iff the stop watch is not started.

splitStartMillis

protected long splitStartMillis
The time where the last split was started (in milliseconds). -1 iff no split was started.

started

protected boolean started
true iff the stop watch was started more often than stopped.
Constructor Detail

Stopwatch

public Stopwatch(java.lang.String desc)
Creates a new stop watch with descriptive text.
Parameters:
desc - a value of type String

Stopwatch

public Stopwatch()
Creates a new stop watch w/o descriptive text.
Method Detail

getDescription

public java.lang.String getDescription()
Returns the descriptive text used when creating the stop watch plus. If the description was null this method return the empty string. If it was neither null nor empty, it returns the descriptive text plus space appended.
Returns:
a String value

start

public void start(java.lang.String s)
Starts the stop watch with a start text. Starting a stopwatch more than once throws an IllegalArgumentException.
Parameters:
s - a value of type String

start

public void start()
Starts the stop watch w/o a start text.
Parameters:
nil - a value of type

split

public void split(java.lang.String s)
Starts a new segment in the stopped time with descriptive text. The elapsed time of each segment is measured separately. If the stop watch was not started, it throws an IllegalArgumentException.
Parameters:
s - a value of type String

split

public void split()
Starts a new segment in the stopped time w/o descriptive text.

stop

public void stop(java.lang.String s)
Stops the stop watch and returns the accumulated result. If the stop watch was not started, it throws an IllegalArgumentException.
Parameters:
s - The descriptive text of the last segment

stop

public void stop()
Stops the stop watch and returns the accumulated result.

reset

public void reset(java.lang.String desc)
Resets this stopwatch to its initial state.
Parameters:
desc - a String value

reset

public void reset()

get

public java.util.Vector get()
Returns the accumulated result after the watch was stopped.
Returns:
a Vector value

toString

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

main

public static void main(java.lang.String[] args)
Mini test environment.
Parameters:
args - a String[] value