Class SimpleActiveTimer

    • Constructor Detail

      • SimpleActiveTimer

        public SimpleActiveTimer​(CurrentNanosSource nanoSource)
        Create an instance that is not started yet.
        Parameters:
        nanoSource - A source of the current time, represented in nanoseconds.
    • Method Detail

      • createAndStart

        public static SimpleActiveTimer createAndStart​(CurrentNanosSource nanoSource)
        Create an instance and start it.
        Parameters:
        nanoSource - A source of the current time, represented in nanoseconds.
        Returns:
        A SimpleActiveTimer instance that has been started.
      • addTimerStartedListener

        public void addTimerStartedListener​(ListenableTimer.StateChangeListener timerStartedListener)
        Description copied from interface: ListenableTimer
        Add a StateChangeListener to the list of listeners that will be invoked when the timer is started. If the timer has already been started, calling this method will result in the listener being invoked immediately.
        Specified by:
        addTimerStartedListener in interface ListenableTimer
        Parameters:
        timerStartedListener - The StateChangeListener to add.
      • addTimerStoppedListener

        public void addTimerStoppedListener​(ListenableTimer.StateChangeListener timerStoppedListener)
        Description copied from interface: ListenableTimer
        Add a StateChangeListener to the list of listeners that will be invoked when the timer is stopped. If the timer has already been stopped, calling this method will result in the listener being invoked immediately.
        Specified by:
        addTimerStoppedListener in interface ListenableTimer
        Parameters:
        timerStoppedListener - The StateChangeListener to add.
      • hasBeenStarted

        public boolean hasBeenStarted()
        Description copied from interface: QueryableTimer
        Has the timer been started?
        Specified by:
        hasBeenStarted in interface QueryableTimer
        Returns:
        True if the timer has been started.
      • isRunning

        public boolean isRunning()
        Description copied from interface: QueryableTimer
        Is the timer currently running?
        Specified by:
        isRunning in interface QueryableTimer
        Returns:
        True if the timer is currently running.
      • isStopped

        public boolean isStopped()
        Description copied from interface: QueryableTimer
        Has the timer been stopped?
        Specified by:
        isStopped in interface QueryableTimer
        Returns:
        True if the timer has been stopped.
      • startTimer

        public void startTimer()
        Start the timer.
        Throws:
        IllegalStateException - if the timer has already been started.
      • elapsed

        public Duration elapsed()
        Description copied from interface: QueryableTimer
        What is the elapsed time of this timer?

        If the timer is running, this is the elapsed time since it was started, until the current time. If the timer has been stopped, this is the elapsed time from the moment it was started until the moment it was stopped. (When the timer has been stopped, this value does not change.)

        Specified by:
        elapsed in interface QueryableTimer
        Returns:
        The amount of time that has elapsed since the timer was started.
      • stopTimer

        public Duration stopTimer()
        Description copied from interface: StoppableTimer
        Stop the timer, and obtain the elapsed time since it was started.
        Specified by:
        stopTimer in interface StoppableTimer
        Returns:
        The elapsed time since the timer was started.
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object