Package rsb.util

Class Timer

java.lang.Object
rsb.util.Timer

public class Timer extends Object
A Timer
  • Constructor Summary

    Constructors
    Constructor
    Description
    Timer(long period)
    Instantiates a new Timer with a given time period in milliseconds.
  • Method Summary

    Modifier and Type
    Method
    Description
    static String
    format(long time)
    Converts milliseconds to a String in the format hh:mm:ss.
    long
    Returns the number of milliseconds elapsed since the start time.
    long
    Returns the number of milliseconds remaining until the timer is up.
    boolean
    Returns true if this timer's time period has not yet elapsed.
    void
    Restarts this timer using its period.
    long
    setEndIn(long ms)
    Sets the end time of this timer to a given number of milliseconds from the time it is called.
    static long
    timeFromMark(long ms)
     
    Returns a formatted String of the time elapsed.
    Returns a formatted String of the time remaining.
    static boolean
    waitCondition(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

    Methods inherited from class java.lang.Object

    equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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()
      Returns true if this timer's time period has not yet elapsed.
      Returns:
      true if 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

      public String toElapsedString()
      Returns a formatted String of the time elapsed.
      Returns:
      The elapsed time formatted hh:mm:ss.
    • toRemainingString

      public String 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

      public static boolean waitCondition(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
      Parameters:
      condition - the boolean conditional to check for
      timeout - the time limit for waiting for the condition check to return true
      Returns:
      true if the task was executed; otherwise false
    • format

      public static String format(long time)
      Converts milliseconds to a String in the format hh:mm:ss.
      Parameters:
      time - The number of milliseconds.
      Returns:
      The formatted String.