Class Stopwatch

java.lang.Object
lol.trq.helios.anim.Stopwatch

public final class Stopwatch extends Object
Measures elapsed time since the last reset; the building block for cooldowns and delays.
  • Constructor Details

    • Stopwatch

      public Stopwatch()
      Starts a stopwatch on the system clock.
    • Stopwatch

      public Stopwatch(Clock clock)
      Starts a stopwatch.
      Parameters:
      clock - the time source
  • Method Details

    • reset

      public Stopwatch reset()
      Restarts from zero.
      Returns:
      this stopwatch
    • millis

      public long millis()
      Returns the elapsed time.
      Returns:
      milliseconds since the last reset
    • nanos

      public long nanos()
      Returns the elapsed time.
      Returns:
      nanoseconds since the last reset
    • elapsed

      public boolean elapsed(long millis)
      Returns whether at least some time has passed.
      Parameters:
      millis - the time
      Returns:
      true once millis have elapsed
    • elapsedAndReset

      public boolean elapsedAndReset(long millis)
      Returns whether some time has passed and, if so, resets: a cooldown in one call.
      Parameters:
      millis - the time
      Returns:
      true at most once per millis