org.esa.beam.util
Class StopWatch

java.lang.Object
  extended by org.esa.beam.util.StopWatch

public class StopWatch
extends Object

The StopWatch class is a (very) simple utility class that allows to measure the time passed between two user defined events.

Here is an example:

      ...
      private final StopWatch stopWatch = new StopWatch();
      ...
      void doATimeConsumingThing() {
          stopWatch.start();
          ...
          stopWatch.end();
          Debug.trace("Time needed: " + stopWatch);
      }
      ...
 

Version:
$Revision$ $Date$
Author:
Norman Fomferra

Constructor Summary
StopWatch()
          Construct a new stop watch object.
 
Method Summary
 long getEndTime()
          Gets the user defined end time in milliseconds (the one that was set when the stop() method was called).
 long getStartTime()
          Gets the user defined start time in milliseconds (the one that was set when the start() method was called).
 long getTimeDiff()
          Gets the elapsed time between start time and end time.
 String getTimeDiffString()
          Returns the elapsed time between start and end as a string in the format "hours:minutes:seconds", with seconds given as a decimal floating point number.
static String getTimeString(long millis)
          Utility method that converts a given time in milliseconds in the format "hours:minutes:seconds", with seconds given as a decimal floating point number.
 void start()
          Defines the start time by calling java.lang.System.currentTimeMillis().
 void stop()
          Defines the end time by calling java.lang.System.currentTimeMillis().
 void stopAndTrace(String label)
           
 String toString()
          Return a string representation of the elapsed time by calling getTimeDiffString().
 void trace(String label)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

StopWatch

public StopWatch()
Construct a new stop watch object. The constructor simply calls start().

Method Detail

start

public void start()
Defines the start time by calling java.lang.System.currentTimeMillis().


stop

public void stop()
Defines the end time by calling java.lang.System.currentTimeMillis().


getStartTime

public long getStartTime()
Gets the user defined start time in milliseconds (the one that was set when the start() method was called).


getEndTime

public long getEndTime()
Gets the user defined end time in milliseconds (the one that was set when the stop() method was called).


getTimeDiff

public long getTimeDiff()
Gets the elapsed time between start time and end time.


getTimeDiffString

public String getTimeDiffString()
Returns the elapsed time between start and end as a string in the format "hours:minutes:seconds", with seconds given as a decimal floating point number.

Returns:
the elapsed time as a string

getTimeString

public static String getTimeString(long millis)
Utility method that converts a given time in milliseconds in the format "hours:minutes:seconds", with seconds given as a decimal floating point number.

Parameters:
millis - the time in milliseconds
Returns:
the time as a string

toString

public String toString()
Return a string representation of the elapsed time by calling getTimeDiffString().

Overrides:
toString in class Object

stopAndTrace

public void stopAndTrace(String label)

trace

public void trace(String label)


Copyright © 2002-2012 Brockmann Consult GmbH. All Rights Reserved.