Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.9.0)

E52944-01


oracle.javatools.util
Class Chronometer

java.lang.Object
  extended by oracle.javatools.util.Chronometer


public final class Chronometer
extends java.lang.Object

This class implements a virtual digital stopwatch (or chronometer), providing basic and useful functionalities for time measurement, such as start(), stop(), multiple laps and total elapsed running time.

Since:
11.1.1.7.2

Nested Class Summary
static class Chronometer.Precision
          Defines the method to be utilized by a Chronometer instance in order to obtain current time.

 

Constructor Summary
Chronometer()
          Default constructor.
Chronometer(Chronometer.Precision precision)
          Constructor.

 

Method Summary
 int countLaps()
          The total count of laps this chronometer is currently keeping track of.
 java.lang.String dumpTimes()
          This method will dump the entire content of the chronometer to a string.
static java.lang.String format(long time)
          Converts a time interval to a human-readable text up to the millisecond.
static java.lang.String format(long time, Chronometer.Precision precision)
          Converts a time interval to a human-readable text up to the specificed precision.
 long getCurrentLap()
          Gets the running time elapsed for the current lap, which excludes any time elapsed while the chronometer was stopped.
 long getElapsedTime()
          Total elapsed time during which the chronometer is or was running.
 long getLap(java.lang.String label)
          Gets the running time elapsed for the given labeled lap.
 boolean isRunning()
           
 void newLap(java.lang.String label)
          Starts of a new labeled lap and also stops the previous one, if any.
 void reset()
          Completely resets the chronometer, putting it in stop state.
 void start()
          Starts the chronometer.
 long stop()
          Completely "freezes" the chronometer, including any current lap.
 java.lang.String toString()
          Converts the current elapsed time to a human-readable text up to the chronometer's precision.
 java.lang.String toString(java.lang.String label)
          Converts the current elapsed time for a given lap to a human-readable text up to the chronometer's precision.

 

Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait

 

Constructor Detail

Chronometer

public Chronometer()
Default constructor. Equivalent to Chronometer(Precision.Milliseconds.

Chronometer

public Chronometer(Chronometer.Precision precision)
Constructor.
Parameters:
precision - The chronometer's precision

Method Detail

stop

public long stop()

Completely "freezes" the chronometer, including any current lap.

Calling start() after a stop means that the chronometer will restart exactly from the last stop. In other words, the time elapsed between these two sequential calls: stop() -> start() won't count.

Returns:
The result of getElapsedTime()

reset

public void reset()
Completely resets the chronometer, putting it in stop state. All existing laps are cleared and elapsed time counter is set to 0 (zero).

start

public void start()

Starts the chronometer.

Calling start after a stop() means that the chronometer will restart exactly from the last stop. In other words, the time elapsed between these two sequential calls: stop() -> start() won't count.

If the chronometer is already running, an IllegalStateException will be thrown.


isRunning

public boolean isRunning()

getElapsedTime

public long getElapsedTime()
Total elapsed time during which the chronometer is or was running. This excludes any time elapsed while the chronometer was stopped.
Returns:
Total elapsed time in milliseconds.

countLaps

public int countLaps()
The total count of laps this chronometer is currently keeping track of.
Returns:
Total number of laps

newLap

public void newLap(java.lang.String label)

Starts of a new labeled lap and also stops the previous one, if any.

The chronometer has to be running, othersize an IllegalStateException will be thrown.

Parameters:
label - Non-null label for the new lap

getLap

public long getLap(java.lang.String label)
Gets the running time elapsed for the given labeled lap. This excludes any time elapsed while the chronometer was stopped.
Parameters:
label - Label of the lap to retrieve
Returns:
long Elapsed running time for the specified lap in milliseconds or 0 (zero) if no laps are associated with the label

getCurrentLap

public long getCurrentLap()
Gets the running time elapsed for the current lap, which excludes any time elapsed while the chronometer was stopped.
Returns:
Elapsed running time for the current lap in milliseconds or 0 (zero) if the is no current lap

format

public static java.lang.String format(long time)
Converts a time interval to a human-readable text up to the millisecond.
Parameters:
time - Elapsed time
Returns:
The elapsed time in human-readable format

format

public static java.lang.String format(long time,
                                      Chronometer.Precision precision)
Converts a time interval to a human-readable text up to the specificed precision.
Parameters:
time - Elapsed time
Returns:
The elapsed time in a human-readable format
Throws:
java.lang.NullPointerException - If given precision is null

dumpTimes

public java.lang.String dumpTimes()
This method will dump the entire content of the chronometer to a string. This includes the total elapsed time and each existing lap's elapsed time as well.
Returns:
A string containing the entire content of the chronometer.

toString

public java.lang.String toString()
Converts the current elapsed time to a human-readable text up to the chronometer's precision.
Overrides:
toString in class java.lang.Object
Returns:
The elapsed time in human-readable format

toString

public java.lang.String toString(java.lang.String label)
Converts the current elapsed time for a given lap to a human-readable text up to the chronometer's precision.
Parameters:
label - The label associated with the desired lap
Returns:
The elapsed time for the given lap in human-readable format

Skip navigation links

Oracle Fusion Middleware Java API Reference for Oracle Extension SDK Reference
11g Release 1 (11.1.1.9.0)

E52944-01


Copyright © 1997, 2015, Oracle. All rights reserved.