kiwi.util
Class IntervalTimer

java.lang.Object
  extended bykiwi.util.IntervalTimer
All Implemented Interfaces:
Resource

public class IntervalTimer
extends java.lang.Object
implements Resource

A class that represents an interval timer. The timer can be started, stopped, resumed, and cleared, much like a stopwatch.

Author:
Mark Lindner, PING Software Group

Field Summary
private  long accum_time
           
private  java.lang.String name
           
private  boolean running
           
private  long start
           
private  long stop
           
private  long time
           
 
Constructor Summary
IntervalTimer()
          Construct a new IntervalTimer.
 
Method Summary
 void clear()
          Clear a timer.
 java.lang.String getName()
          Get the name for this timer.
 long getTime()
          Get the accumulated time for the timer.
 boolean isRunning()
          Determine if the timer is currently running.
 void release()
          Release the timer.
 void reserve()
          Reserve the timer.
 void resume()
          Resume a stopped timer.
 void setName(java.lang.String name)
          Set the name for this timer.
 void start()
          Start the timer.
 void stop()
          Stop the timer.
 java.lang.String toString()
          Create a string representation of the timer, which includes its name and accumulated time.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

start

private long start

stop

private long stop

time

private long time

accum_time

private long accum_time

running

private boolean running

name

private java.lang.String name
Constructor Detail

IntervalTimer

public IntervalTimer()
Construct a new IntervalTimer.

Method Detail

getName

public java.lang.String getName()
Get the name for this timer.

Returns:
The timer's name.

setName

public void setName(java.lang.String name)
Set the name for this timer.

Parameters:
name - The new name for the timer.

isRunning

public boolean isRunning()
Determine if the timer is currently running. Note that a timer is not running in the sense that a thread is running; no code is being executed while the timer is running.

Returns:
true if the timer is running and false otherwise.

start

public void start()
Start the timer. If the timer is already running, this method does nothing.


stop

public void stop()
Stop the timer. If the timer is not running, this method does nothing.


resume

public void resume()
Resume a stopped timer. If the timer is running, this method does nothing.


clear

public void clear()
Clear a timer. Regardless of whether the timer is running or not, it is stopped and the accumulated time is reset to 0.


getTime

public long getTime()
Get the accumulated time for the timer. Time accumulates while the timer is running, but not while it is stopped.

Returns:
The amount of time that this timer has accumulated, in microseconds, or -1 if the timer is currently running.

toString

public java.lang.String toString()
Create a string representation of the timer, which includes its name and accumulated time.


reserve

public void reserve()
Reserve the timer. This method clears the timer.

Specified by:
reserve in interface Resource

release

public void release()
Release the timer. This method clears the timer.

Specified by:
release in interface Resource