Package rsb.util
Class Timer
java.lang.Object
rsb.util.Timer
A Timer
-
Constructor Summary
ConstructorsConstructorDescriptionTimer(long period) Instantiates a new Timer with a given time period in milliseconds. -
Method Summary
Modifier and TypeMethodDescriptionstatic Stringformat(long time) Converts milliseconds to a String in the format hh:mm:ss.longReturns the number of milliseconds elapsed since the start time.longReturns the number of milliseconds remaining until the timer is up.booleanReturnstrueif this timer's time period has not yet elapsed.voidreset()Restarts this timer using its period.longsetEndIn(long ms) Sets the end time of this timer to a given number of milliseconds from the time it is called.static longtimeFromMark(long ms) Returns a formatted String of the time elapsed.Returns a formatted String of the time remaining.static booleanwaitCondition(BooleanSupplier condition, long timeout) Allows a condition to be passed to check and a timeout for the condition to pass Continuously checks the condition in a while loop on an executor thread
-
Constructor Details
-
Timer
public Timer(long period) Instantiates a new Timer with a given time period in milliseconds.- Parameters:
period- Time period in milliseconds.
-
-
Method Details
-
getElapsed
public long getElapsed()Returns the number of milliseconds elapsed since the start time.- Returns:
- The elapsed time in milliseconds.
-
getRemaining
public long getRemaining()Returns the number of milliseconds remaining until the timer is up.- Returns:
- The remaining time in milliseconds.
-
isRunning
public boolean isRunning()Returnstrueif this timer's time period has not yet elapsed.- Returns:
trueif the time period has not yet passed.
-
reset
public void reset()Restarts this timer using its period. -
setEndIn
public long setEndIn(long ms) Sets the end time of this timer to a given number of milliseconds from the time it is called. This does not edit the period of the timer (so will not affect operation after reset).- Parameters:
ms- The number of milliseconds before the timer should stop running.- Returns:
- The new end time.
-
toElapsedString
Returns a formatted String of the time elapsed.- Returns:
- The elapsed time formatted hh:mm:ss.
-
toRemainingString
Returns a formatted String of the time remaining.- Returns:
- The remaining time formatted hh:mm:ss.
-
timeFromMark
public static long timeFromMark(long ms) -
waitCondition
Allows a condition to be passed to check and a timeout for the condition to pass Continuously checks the condition in a while loop on an executor thread- Parameters:
condition- the boolean conditional to check fortimeout- the time limit for waiting for the condition check to return true- Returns:
trueif the task was executed; otherwisefalse
-
format
Converts milliseconds to a String in the format hh:mm:ss.- Parameters:
time- The number of milliseconds.- Returns:
- The formatted String.
-