Package org.robwork.sdurw_common
Class Timer
- java.lang.Object
-
- org.robwork.sdurw_common.Timer
-
public class Timer extends java.lang.Object
The timer class provides an easy to use platform independent timer
In Windows the expected resolution is approx. 16ms.
In Linux the expected resolution is approx. 1ms
-
-
Constructor Summary
Constructors Constructor Description Timer()
Constructor
This implicitly starts the timer.Timer(int timems)
constructor - initialize the timer to a specified value.Timer(int hh, int mm)
constructor - initialize the timer to a specified value.Timer(int hh, int mm, int ss)
constructor - initialize the timer to a specified value.Timer(int hh, int mm, int ss, int ms)
constructor - initialize the timer to a specified value.Timer(long cPtr, boolean cMemoryOwn)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static double
currentTime()
Returns system clock in seconds
Warning: The date/time at which this timer counts from is platform-specific, so
you should not use it for getting the calendar time.static int
currentTimeMs()
Returns system clock in milli-seconds
Warning: The date/time at which this timer counts from is platform-specific, so
you should not use it for getting the calendar time.static int
currentTimeSec()
Returns system clock in hole seconds
Warning: The date/time at which this timer counts from is platform-specific, so
you should not use it for getting the calendar time.static int
currentTimeUs()
Returns system clock in micro-seconds.
Warning: The date/time at which this timer counts from is platform-specific, so
you should not use it for getting the calendar time.void
delete()
static long
getCPtr(Timer obj)
double
getTime()
The time the timer has been running.
The time passed while the timer has been paused are not included in
the running time.int
getTimeMs()
The time the timer has been running in mili seconds.
see getTime
int
getTimeSec()
The time the timer has been running in hole seconds.
see getTime
boolean
isPaused()
Returns true if the timer is pausedvoid
pause()
Pause the timer
The timer stops counting.void
reset()
Reset the timer
The timer is set back to zero and starts counting.
It is OK to call reset() on a timer that has already been started:
The time will just be set back to zero again.void
resetAndPause()
Resets and pauses the timer
The timer is set to zero and paused
It is OK to call reset() on a timer that has already been started:
The time will just be set back to zero again.void
resetAndResume()
Resets and stats the timer
Same as reset()
The timer is set to zero and starts counting
It is OK to call reset() on a timer that has already been started:
The time will just be set back to zero again.void
resume()
Resume the timer after a pause.
The timer starts counting again.
It is OK to call resume() on a timer that is already counting: The
timer keeps counting and nothing is done.static void
sleepMs(int period)
Sleeps for a period of time
static void
sleepUs(int period)
Sleeps for a period of time
java.lang.String
toString()
returns a string describing the time.java.lang.String
toString(java.lang.String format)
returns a string describing the time.
-
-
-
Constructor Detail
-
Timer
public Timer(long cPtr, boolean cMemoryOwn)
-
Timer
public Timer()
Constructor
This implicitly starts the timer.
-
Timer
public Timer(int timems)
constructor - initialize the timer to a specified value. This does not start the
timer.- Parameters:
timems
- [in] time in ms
-
Timer
public Timer(int hh, int mm, int ss, int ms)
constructor - initialize the timer to a specified value. This does not start the
timer.- Parameters:
hh
- [in] hoursmm
- [in] minutesss
- [in] secondsms
- [in] milli seconds
-
Timer
public Timer(int hh, int mm, int ss)
constructor - initialize the timer to a specified value. This does not start the
timer.- Parameters:
hh
- [in] hoursmm
- [in] minutesss
- [in] seconds
-
Timer
public Timer(int hh, int mm)
constructor - initialize the timer to a specified value. This does not start the
timer.- Parameters:
hh
- [in] hoursmm
- [in] minutes
-
-
Method Detail
-
getCPtr
public static long getCPtr(Timer obj)
-
delete
public void delete()
-
isPaused
public boolean isPaused()
Returns true if the timer is paused- Returns:
- True is paused
-
reset
public void reset()
Reset the timer
The timer is set back to zero and starts counting.
It is OK to call reset() on a timer that has already been started:
The time will just be set back to zero again.
-
resetAndPause
public void resetAndPause()
Resets and pauses the timer
The timer is set to zero and paused
It is OK to call reset() on a timer that has already been started:
The time will just be set back to zero again.
-
resetAndResume
public void resetAndResume()
Resets and stats the timer
Same as reset()
The timer is set to zero and starts counting
It is OK to call reset() on a timer that has already been started:
The time will just be set back to zero again.
-
pause
public void pause()
Pause the timer
The timer stops counting. As long as the timer has not been resumed
(see resume()) or restarted (see reset()) the timer value (see
getTime()) will stay the same.
Is is OK to call pause() on a timer that has already been paused: The
timer will just stay paused and nothing is changed.
-
resume
public void resume()
Resume the timer after a pause.
The timer starts counting again.
It is OK to call resume() on a timer that is already counting: The
timer keeps counting and nothing is done.
-
getTime
public double getTime()
The time the timer has been running.
The time passed while the timer has been paused are not included in
the running time. The timer is paused when pause() has been
called and counting is resumed when resume() has been called.
It is perfectly OK and natural to call getTime() on a running timer,
i.e. a timer that has not been paused.
A call of reset() resets the running time to zero.
- Returns:
- Time in seconds
-
getTimeSec
public int getTimeSec()
The time the timer has been running in hole seconds.
see getTime
- Returns:
- Time in hole seconds
-
getTimeMs
public int getTimeMs()
The time the timer has been running in mili seconds.
see getTime
- Returns:
- Time in mili seconds
-
toString
public java.lang.String toString(java.lang.String format)
returns a string describing the time. The format of the time is described using
format- Parameters:
format
- [in] the format is on the form:
hh:mm:ss --> 05:06:08
h:m:s --> 5:6:8- Returns:
- a formated time string
-
toString
public java.lang.String toString()
returns a string describing the time. The format of the time is described using
format
- Overrides:
toString
in classjava.lang.Object
- Returns:
- a formated time string
-
currentTimeSec
public static int currentTimeSec()
Returns system clock in hole seconds
Warning: The date/time at which this timer counts from is platform-specific, so
you should not use it for getting the calendar time. It's really only meant for
calculating wall time differences.
-
currentTimeMs
public static int currentTimeMs()
Returns system clock in milli-seconds
Warning: The date/time at which this timer counts from is platform-specific, so
you should not use it for getting the calendar time. It's really only meant for
calculating wall time differences.
-
currentTimeUs
public static int currentTimeUs()
Returns system clock in micro-seconds.
Warning: The date/time at which this timer counts from is platform-specific, so
you should not use it for getting the calendar time. It's really only meant for
calculating wall time differences.
Notice: The timer cannot hold times longer than approx. 2100second.
-
currentTime
public static double currentTime()
Returns system clock in seconds
Warning: The date/time at which this timer counts from is platform-specific, so
you should not use it for getting the calendar time. It's really only meant for
calculating wall time differences.
-
sleepMs
public static void sleepMs(int period)
Sleeps for a period of time
- Parameters:
period
- [in] the time in miliseconds to sleep
-
sleepUs
public static void sleepUs(int period)
Sleeps for a period of time
- Parameters:
period
- [in] the time in microseconds to sleep
-
-