hmi.util
Class Stopwatch

java.lang.Object
  extended by hmi.util.Stopwatch

public class Stopwatch
extends Object

Stopwatch is a class for performing timing. A Stopwatch starts running immediately upon creation. It can at any time be reset to 0 by calling start() or reset(). The current stopwatch time is shown on the Console with show(); (The latter will not stop or reset the stopwatch; it keeps running) If a series of timeintervals must be measured, it is possible to call showLap() rather than show(). Consecutive showLap() calls show the time between these calls, whereas show() always show the accumulated time. Timing can also be done without Console output, by calling read() instead of show(), or readLap() instead of showLap(). Finally, Stopwatch offers a delay(long) method, which has nothing to do with the stopwatch instances as such. It performs a Thread.sleep(), and catches the annoying exception.

Author:
Job Zwiers

Field Summary
private  long currenttime
           
private  long lapstart
           
private  String name
           
private static int NANOSPERMICROSECOND
           
private static int NANOSPERMILLISECOND
           
private static int NANOSPERSECOND
           
private  long starttime
           
private static int stopwatchcount
           
private static int TESTDELAY1
           
private static int TESTDELAY2
           
 
Constructor Summary
Stopwatch()
          create a new numbered Stopwatch.
Stopwatch(String name)
          create a new named Stopwatch.
 
Method Summary
static void delay(long d)
          same as Thread.sleep(), but catches and ignores Exceptions.
 String getName()
          returns the name of this Stopwatch.
static void main(String[] arg)
           
 void showMicroseconds()
          read the current time for the stopwatch, relative to the start time, and show it on the hmi.util.Console, in microseconds
 void showMicroseconds(String message)
          read the current time for the stopwatch, relative to the start time, and show it on the hmi.util.Console, in microseconds
 void showMilliseconds()
          read the current time for the stopwatch, relative to the start time, and show it on the hmi.util.Console, in seconds
 void showMilliseconds(String message)
          read the current time for the stopwatch, relative to the start time, and show it on the hmi.util.Console, in milliseconds
 long showMillisecondsLap()
          read the "lap" time for the stopwatch, relative to reading the last lap time, or relative to starttime if this is the first readLap call.
 void showNanoseconds()
           
 void showNanoseconds(String message)
          read the current time for the stopwatch, relative to the start time, and show it on the hmi.util.Console, in nanoseconds.
 void showSeconds()
          read the current time for the stopwatch, relative to the start time, and show it on the hmi.util.Console, in seconds
 void showSeconds(String message)
          read the current time for the stopwatch, relative to the start time, and show it on the hmi.util.Console, in seconds
 void start()
          starts/resets the stopwatch, by reading the current system time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NANOSPERSECOND

private static final int NANOSPERSECOND
See Also:
Constant Field Values

NANOSPERMILLISECOND

private static final int NANOSPERMILLISECOND
See Also:
Constant Field Values

NANOSPERMICROSECOND

private static final int NANOSPERMICROSECOND
See Also:
Constant Field Values

TESTDELAY1

private static final int TESTDELAY1
See Also:
Constant Field Values

TESTDELAY2

private static final int TESTDELAY2
See Also:
Constant Field Values

starttime

private long starttime

currenttime

private long currenttime

lapstart

private long lapstart

name

private String name

stopwatchcount

private static int stopwatchcount
Constructor Detail

Stopwatch

public Stopwatch()
create a new numbered Stopwatch. The name is of the form "Stopwatch ". It starts running right away.


Stopwatch

public Stopwatch(String name)
create a new named Stopwatch. It starts running right away.

Method Detail

getName

public String getName()
returns the name of this Stopwatch.


start

public void start()
starts/resets the stopwatch, by reading the current system time. The latter is returned.


showSeconds

public void showSeconds()
read the current time for the stopwatch, relative to the start time, and show it on the hmi.util.Console, in seconds


showSeconds

public final void showSeconds(String message)
read the current time for the stopwatch, relative to the start time, and show it on the hmi.util.Console, in seconds


showMilliseconds

public void showMilliseconds()
read the current time for the stopwatch, relative to the start time, and show it on the hmi.util.Console, in seconds


showMilliseconds

public final void showMilliseconds(String message)
read the current time for the stopwatch, relative to the start time, and show it on the hmi.util.Console, in milliseconds


showMicroseconds

public final void showMicroseconds()
read the current time for the stopwatch, relative to the start time, and show it on the hmi.util.Console, in microseconds


showMicroseconds

public final void showMicroseconds(String message)
read the current time for the stopwatch, relative to the start time, and show it on the hmi.util.Console, in microseconds


showNanoseconds

public final void showNanoseconds(String message)
read the current time for the stopwatch, relative to the start time, and show it on the hmi.util.Console, in nanoseconds.


showNanoseconds

public final void showNanoseconds()

showMillisecondsLap

public long showMillisecondsLap()
read the "lap" time for the stopwatch, relative to reading the last lap time, or relative to starttime if this is the first readLap call. and show it on the hmi.util.Console. The lap time is in milliseconds. (There is no microseconds or even nanoseconds version of showLap, since the Console.print action takes milliseconds itself).


delay

public static void delay(long d)
same as Thread.sleep(), but catches and ignores Exceptions.


main

public static void main(String[] arg)