ElapsedTimer
A very simple timer that keeps track of how much time has been elapsed. This can be used to create time-based loops. As of Pathfinder v0.10.7, the functionality of ElapsedTimer has been effectively encapsulated in the Time class: Time.runFor(double, Runnable).
As of Pathfinder v2.1.0, there are some new methods here:
wait(double)waitThenRun(Runnable, double)runThenWait(Runnable, double)runFor(Runnable, double)
Methods
ElapsedTimer()
Creates a new ElapsedTimer. The timer will NOT start automatically.
ElapsedTimer(boolean shouldStart)
Creates a new ElapsedTimer, and based on a boolean, potentially starts the timer.
waitThenRun(Runnable runnable, double timeMs)
Static method. Waits for a certain amount of time then runs a Runnable.
wait(double timeMs)
Static method. Waits for a certain amount of time (in milliseconds).
runThenWait(Runnable runnable, double timeMs)
Static method. Runs a Runnable then waits for a certain amount of time.
runFor(Runnable runnable, double timeMs)
Static method. Runs a Runnable repeatedly for a certain amount of time (in milliseconds).
start()
Starts the timer. Sets the internal start time to the current system time.
getElapsed()
Returns the elapsed time in milliseconds since the timer was started or reset.
getTimeSpan()
Returns a TimeSpan object representing the amount of elapsed time.
elapsedMilliseconds()
Returns the elapsed time in milliseconds. Alias for getElapsed().
elapsedMs()
Returns the elapsed time in milliseconds. Alias for getElapsed().
elapsedSeconds()
Returns the elapsed time in seconds.
isElapsedMoreThan(long time)
Checks if the elapsed time is greater than a provided value (in milliseconds).
isElapsedLessThan(long time)
Checks if the elapsed time is less than a provided value (in milliseconds).
isElapsedMoreThan(double time)
Checks if the elapsed time is greater than a provided value (in milliseconds).
isElapsedLessThan(double time)
Checks if the elapsed time is less than a provided value (in milliseconds).
hasStarted()
Checks if the ElapsedTimer has been started yet.
reset()
Resets the timer. The elapsed time will be 0 immediately after calling this method.