Package org.freedesktop.dbus.utils
Class TimeMeasure
- java.lang.Object
-
- org.freedesktop.dbus.utils.TimeMeasure
-
public class TimeMeasure extends java.lang.ObjectUtility class for time measurements. Instances may be reset for reuse.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static interfaceTimeMeasure.ITimeMeasureFormat
-
Field Summary
Fields Modifier and Type Field Description private longstartTmStart time in nanoseconds.private TimeMeasure.ITimeMeasureFormattmfFormatter used fortoString()
-
Constructor Summary
Constructors Constructor Description TimeMeasure()Create a new instance, used a formatter converting everything >= 5000 ms to seconds (X.Y -> 6.1).TimeMeasure(TimeMeasure.ITimeMeasureFormat _formatter)Create a new instance using _ts millis as
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description longgetElapsed()Returns the elapsed time in milliseconds.longgetElapsedAndReset()java.lang.StringgetElapsedFormatted(java.text.DateFormat _dateFormat)Formats the elapsed time using the given dateFormatter.(package private) java.lang.StringgetElapsedFormatted(java.text.DateFormat _dateFormat, long _elapsedTime)Same as above, used for proper unit testing.longgetElapsedSeconds()Returns the elapsed time in seconds.longgetStartTime()Returns the start time in milliseconds.TimeMeasurereset()Resets the start time.(package private) voidsetStartTm(long _tm)Change the start time (for unit testing only!).java.lang.StringtoString()Returns the elapsed time in milliseconds formatted as string.
-
-
-
Field Detail
-
startTm
private volatile long startTm
Start time in nanoseconds.
-
tmf
private final TimeMeasure.ITimeMeasureFormat tmf
Formatter used fortoString()
-
-
Constructor Detail
-
TimeMeasure
public TimeMeasure(TimeMeasure.ITimeMeasureFormat _formatter)
Create a new instance using _ts millis as- Parameters:
_formatter- formatter to use for toString() call
-
TimeMeasure
public TimeMeasure()
Create a new instance, used a formatter converting everything >= 5000 ms to seconds (X.Y -> 6.1).
-
-
Method Detail
-
reset
public final TimeMeasure reset()
Resets the start time.- Returns:
- the object
-
getStartTime
public long getStartTime()
Returns the start time in milliseconds.- Returns:
- start time in ms
-
getElapsed
public long getElapsed()
Returns the elapsed time in milliseconds.- Returns:
- elapsed time in ms
-
getElapsedSeconds
public long getElapsedSeconds()
Returns the elapsed time in seconds.- Returns:
- elapsed time in seconds
-
getElapsedFormatted
public java.lang.String getElapsedFormatted(java.text.DateFormat _dateFormat)
Formats the elapsed time using the given dateFormatter. If null is given, a new Formatter with format HH:mm:ss.SSS will be used. The timezone of the given dateFormatter will always be set to 'UTC' to avoid any timezone related offsets.- Parameters:
_dateFormat- date format- Returns:
- formatted string
-
getElapsedFormatted
java.lang.String getElapsedFormatted(java.text.DateFormat _dateFormat, long _elapsedTime)Same as above, used for proper unit testing.- Parameters:
_dateFormat-_elapsedTime-- Returns:
- formatted string
-
setStartTm
void setStartTm(long _tm)
Change the start time (for unit testing only!).- Parameters:
_tm-
-
getElapsedAndReset
public long getElapsedAndReset()
-
toString
public java.lang.String toString()
Returns the elapsed time in milliseconds formatted as string.- Overrides:
toStringin classjava.lang.Object- Returns:
- elapsed time in ms
-
-