org.knowceans.util
Class StopWatch

java.lang.Object
  extended by org.knowceans.util.StopWatch

public class StopWatch
extends java.lang.Object

StopWatch allows to time a java program by simply starting lap-timing, stopping and resetting a stop watch "channel".

Author:
gregor

Method Summary
static StopWatch clear()
          Reset the default named stop watch.
static StopWatch clear(java.lang.String watch)
          Removes the named stop watch, i.e., gets rid of the data and entry in the watches table.
 java.lang.String debug()
          Prints a debug string
static java.lang.String digits(long number, int digits)
          zero-pad the number on the left to create a string of digits characters.
static java.lang.String format(long reltime)
          Format a long time string into hh.mm.ss etc.
static StopWatch get()
          Get the default watch object.
static StopWatch get(java.lang.String watch)
          Get the named watch object.
 java.util.Vector<java.lang.Long> getLaps()
           
 java.lang.String getName()
           
static java.util.Hashtable<java.lang.String,StopWatch> getWatches()
          Get all watches as a table (can be used to add or remove certain watches).
static long lap()
          Get the time of the default watch, relative to the last call to lap.
static long lap(java.lang.String watch)
          Get the time of the named stop watch, relative to the last call to lap or start, whatever was later.
static void main(java.lang.String[] args)
           
static void print()
          Print toString() of the default watch to stdout.
static void print(java.lang.String watch)
          Print toString() to stdout.
static long read()
          Read the current time the default watch is showing.
static long read(java.lang.String watch)
          Read the current time the named watch is showing.
static long start()
          Start the default stop watch.
static long start(java.lang.String watch)
          Starts the named watch.
static long stop()
          Get the stopping time of the default watch and reset it.
static long stop(java.lang.String watch)
          Get the stopping time of the named watch and reset it.
 java.lang.String toString()
          Prints the status of this stop watch, i.e., its name and current reading.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Method Detail

main

public static void main(java.lang.String[] args)
                 throws java.lang.InterruptedException
Throws:
java.lang.InterruptedException

start

public static long start(java.lang.String watch)
Starts the named watch. If the watch existed, the times are kept and the interval that it was paused is subtracted from every interval involving the absolute start time. If it was running, the starting time is simply updated.

Parameters:
watch - string identifier for that watch.
Returns:
current starting time, which is 0 if started the first time and the value of tstop if continued.

start

public static long start()
Start the default stop watch.

Returns:

clear

public static StopWatch clear(java.lang.String watch)
Removes the named stop watch, i.e., gets rid of the data and entry in the watches table. Returns the stop watch just removed to save its data.

Parameters:
watch -

clear

public static StopWatch clear()
Reset the default named stop watch.


get

public static StopWatch get(java.lang.String watch)
Get the named watch object.

Parameters:
watch -
Returns:

get

public static StopWatch get()
Get the default watch object.

Parameters:
watch -
Returns:

lap

public static long lap(java.lang.String watch)
Get the time of the named stop watch, relative to the last call to lap or start, whatever was later.

Parameters:
watch -
Returns:
relative time of last lap (or start), or INVALID if unknown or not running.

lap

public static long lap()
Get the time of the default watch, relative to the last call to lap.

Returns:

read

public static long read(java.lang.String watch)
Read the current time the named watch is showing. If it is stopped, it reads the interval stop - start - paused

Parameters:
watch -
Returns:

read

public static long read()
Read the current time the default watch is showing.

Returns:

stop

public static long stop(java.lang.String watch)
Get the stopping time of the named watch and reset it.

Parameters:
watch -
Returns:
the relative time since the start.

stop

public static long stop()
Get the stopping time of the default watch and reset it.

Returns:

debug

public java.lang.String debug()
Prints a debug string

Returns:

toString

public java.lang.String toString()
Prints the status of this stop watch, i.e., its name and current reading.

Overrides:
toString in class java.lang.Object

print

public static void print(java.lang.String watch)
Print toString() to stdout.

Parameters:
watch -

print

public static void print()
Print toString() of the default watch to stdout.

Parameters:
watch -

format

public static java.lang.String format(long reltime)
Format a long time string into hh.mm.ss etc.

Parameters:
reltime -
Returns:

digits

public static java.lang.String digits(long number,
                                      int digits)
zero-pad the number on the left to create a string of digits characters.

Parameters:
number -
digits -
Returns:

getWatches

public static final java.util.Hashtable<java.lang.String,StopWatch> getWatches()
Get all watches as a table (can be used to add or remove certain watches).

Returns:
the hashtable of watches

getName

public final java.lang.String getName()

getLaps

public final java.util.Vector<java.lang.Long> getLaps()