Package be.panako.util
Class StopWatch
java.lang.Object
be.panako.util.StopWatch
public final class StopWatch
extends java.lang.Object
StopWatch counts the ticks (ns) passed between initialization and invocation
of ticksPassed.
- Author:
- Joren Six
-
Constructor Summary
Constructors Constructor Description StopWatch()Create and start the stop watch. -
Method Summary
Modifier and Type Method Description java.lang.StringformattedToString()static java.lang.StringformattedToString(double secondsPassed)longnanoTicksPassed()voidstart()Starts or restarts the watch.longticksPassed()doubletimePassed(TimeUnit unit)Calculates and returns the time passed in the requested unit.java.lang.StringtoString()static java.lang.StringtoTime(java.lang.String inputResource, int currentSeconds)Returns a 24h time string based on an input resource.Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Constructor Details
-
StopWatch
public StopWatch()Create and start the stop watch.
-
-
Method Details
-
ticksPassed
public long ticksPassed()- Returns:
- The number of ticks passed between initialization and the call to
ticksPassed. In milliseconds or 10^-3 seconds.
-
nanoTicksPassed
public long nanoTicksPassed()- Returns:
- The number of ticks passed between initialization and the call to
ticksPassed. In nanoseconds or 10^-9 seconds.
-
timePassed
Calculates and returns the time passed in the requested unit.- Parameters:
unit- The requested time unit.- Returns:
- The time passed in the requested unit.
-
start
public void start()Starts or restarts the watch. -
toString
public java.lang.String toString()- Overrides:
toStringin classjava.lang.Object
-
toTime
public static java.lang.String toTime(java.lang.String inputResource, int currentSeconds)Returns a 24h time string based on an input resource. E.g. "20120325-235950" + 25 seconds would return "00:00:15"- Parameters:
inputResource- The name of the input resource with a date and time part. E.g. "20120325-235950.wav"currentSeconds- The number of seconds to add to the time part.- Returns:
- E.g. "20120325-235950" + 25 seconds would return "00:00:15"
-
formattedToString
public java.lang.String formattedToString() -
formattedToString
public static java.lang.String formattedToString(double secondsPassed)
-