structure5
Class Clock

java.lang.Object
  extended by structure5.Clock

public class Clock
extends java.lang.Object

A simple object for measuring time. This Clock allows one to measure time between events. Events may be from several milliseconds to several seconds apart. When measuring events that take considerable time (> 1/10th of a second) it is important to counteract the effect of scheduling of other system processes. A Clock has the following operations:

typical use:
    Clock timer = new Clock();
    timer.start();
    for (i = 0; i < 100000; i++);
    timer.stop();
    System.out.println("Time to count to 100000: "+timer.read()+" seconds.");
 


Field Summary
protected  long accum
          The total number of milliseconds elapsed.
protected  boolean running
          An indication of whether or not the clock is running
protected  long strt
          The millisecond that the clock started.
 
Constructor Summary
Clock()
          Constructs a stopwatch for timing events to the milliseconds.
 
Method Summary
 double read()
          Read the value on the stop watch.
 void reset()
          Resets the time on the clock to zero.
 void start()
          Start the clock running.
 void stop()
          Stop the clock.
 java.lang.String toString()
          Generates string representation of clock.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

running

protected boolean running
An indication of whether or not the clock is running


strt

protected long strt
The millisecond that the clock started.


accum

protected long accum
The total number of milliseconds elapsed.

Constructor Detail

Clock

public Clock()
Constructs a stopwatch for timing events to the milliseconds.

Postcondition:
returns a stopped clock
Method Detail

start

public void start()
Start the clock running.

Precondition:
starts clock, begins measuring possibly accumulated time
Postcondition:
clock is stopped

stop

public void stop()
Stop the clock. Time does not accumulate.

Precondition:
clock is running
Postcondition:
stops clock, and accumulates time

read

public double read()
Read the value on the stop watch.

Returns:
A double representing the number of seconds elapsed.
Precondition:
clock is stopped
Postcondition:
returns the accumulated time on the clock

reset

public void reset()
Resets the time on the clock to zero.

Postcondition:
stops running clock and clears the accumulated time

toString

public java.lang.String toString()
Generates string representation of clock.

Overrides:
toString in class java.lang.Object
Returns:
A string representing this clock.
Postcondition:
returns a string representation of the clock