com.sas.util
Class Timer

com.sas.util.Timer
All Implemented Interfaces:
com.sas.beans.PropertyChangeSource, com.sas.beans.VetoableChangeSource, com.sas.ComponentInterface, com.sas.LinkPropertiesInterface, com.sas.ModelInterface, com.sas.util.TimeIntervals, TimerInterface, com.sas.ViewInterface, MultipleValueEventSourceInterface, java.beans.PropertyChangeListener, java.io.ObjectInputValidation, java.io.Serializable, java.util.EventListener

public class Timer
implements TimerInterface

A timer for recording time intervals. All time units are measured in milliseconds. This simple timer class is used for measuring a duration of time; i.e. measure how much time an action takes to execute. For example, an application which executes long operation such as downloading a video from a remote site may use a timer to record how long the download takes and update a status display with the timer duration at regular intervals.

See Also:
Alarm, Serialized Form

Field Summary
static java.lang.String RB_KEY
           
static java.lang.Long Zero
          A Long integer with the value 0. used in event notification;
 
Fields inherited from interface com.sas.util.TimeIntervals
ONE_DAY, ONE_HOUR, ONE_MINUTE, ONE_SECOND, ONE_WEEK
 
Constructor Summary
Timer()
           
 
Method Summary
 boolean equals(java.lang.Object object)
          Test object equality.
 boolean equals(Timer t)
          Test object equality.
 long getDuration()
          Return the number of milliseconds this timer has been running.
static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()
           
 long getStartTime()
          Return this timer's start time.
 long getStopTime()
          Return this timer's stop time.
 int hashCode()
          Compute a hash code.
 boolean isRunning()
          Test if a timer is running.
 void setRunning(boolean running)
          Set the state of the boolean running property.
 void start()
          Start this timer.
 void stop()
          Stop this timer.
 java.lang.String toString()
          Generate a string representation of this timer.
 

Field Detail

RB_KEY

public static final java.lang.String RB_KEY
See Also:
Constant Field Values

Zero

public static java.lang.Long Zero
A Long integer with the value 0. used in event notification;

Constructor Detail

Timer

public Timer()
Method Detail

getExtendedBeanInfo

public static com.sas.beans.ExtendedBeanInfo getExtendedBeanInfo()

equals

public boolean equals(java.lang.Object object)
Test object equality.

Overrides:
equals in class java.lang.Object
Parameters:
object - another object
Returns:
true if the other object is a Timer and it has the same startTime, stopTime, and running status.

equals

public boolean equals(Timer t)
Test object equality.

Parameters:
t - another Timer object
Returns:
true if t has the same startTime, stopTime, and running status.

hashCode

public int hashCode()
Compute a hash code.

Overrides:
hashCode in class java.lang.Object
Returns:
a hash code. Note, since timer objects are mutable, they do not make good candidates for hashtable/dictionary keys.

start

public void start()
Start this timer. This sets its state to running and resets the startTime to the current time. If this timer is already running, it is restarted.

Specified by:
start in interface TimerInterface

stop

public void stop()
Stop this timer. The timer is no longer running; the stop time does not advance. If called on a timer that is not running, it is ignored.

Specified by:
stop in interface TimerInterface

isRunning

public boolean isRunning()
Test if a timer is running.

Specified by:
isRunning in interface TimerInterface
Returns:
true if stop() has not been called since start() was last called; false otherwise.

getStartTime

public long getStartTime()
Return this timer's start time.

Specified by:
getStartTime in interface TimerInterface
Returns:
the time this timer was last started, in number of milliseconds since the Epoch returns 0 if not yet started.

getStopTime

public long getStopTime()
Return this timer's stop time.

Specified by:
getStopTime in interface TimerInterface
Returns:
the time this timer was stopped, in number of milliseconds since the Epoch returns 0 if this timer has not stopped since it was last started.

getDuration

public long getDuration()
Return the number of milliseconds this timer has been running. If this timer has been stopped, this is the difference bewteen the stop time and the start time. If this timer has not been stopped, this is the difference bewteen the current time and the start time. If this timer has never been started, return 0.

Specified by:
getDuration in interface TimerInterface
Returns:
the number of milliseconds this timer has been running. If this timer has been stopped, this is the difference between the stop time and the start time. If this timer has not been stopped, this is the difference between the current time and the start time. If this timer has never been started, return 0.

setRunning

public final void setRunning(boolean running)
Set the state of the boolean running property.

Specified by:
setRunning in interface TimerInterface
Parameters:
running - the new running state. If this is the same as the current state, nothing happens. Otherwise, if true, then call start(), else call stop(). This method is an alias for calling start and stop, and is therefore final. If you override a Timer, you shuld override those methods to change behavior.

toString

public java.lang.String toString()
Generate a string representation of this timer.

Overrides:
toString in class java.lang.Object
Returns:
a string representation of this timer.



Copyright © 2009 SAS Institute Inc. All Rights Reserved.