Interface ElapsedTimeStrategy

  • Functional Interface:
    This is a functional interface and can therefore be used as the assignment target for a lambda expression or method reference.

    @FunctionalInterface
    public interface ElapsedTimeStrategy
    Encapsulates the logic of determining a delay when some criteria is met.
    Author:
    Randall Hauch
    • Method Detail

      • hasElapsed

        boolean hasElapsed()
        Determine if the time period has elapsed since this method was last called.
        Returns:
        true if this invocation caused the thread to sleep, or false if this method did not sleep
      • none

        static ElapsedTimeStrategy none()
        Create an elapsed time strategy that always is elapsed.
        Returns:
        the strategy; never null
      • constant

        static ElapsedTimeStrategy constant​(Clock clock,
                                            long delayInMilliseconds)
        Create a strategy whose time periods are constant.
        Parameters:
        clock - the clock used to determine if sufficient time has elapsed; may not be null
        delayInMilliseconds - the time period; must be positive
        Returns:
        the strategy; never null
      • step

        static ElapsedTimeStrategy step​(Clock clock,
                                        long preStepDelayInMilliseconds,
                                        BooleanSupplier stepFunction,
                                        long postStepDelayInMilliseconds)
        Create a strategy whose time periods start out at one length but then change to another length after another period has elapsed.
        Parameters:
        clock - the clock used to determine if sufficient time has elapsed; may not be null
        preStepDelayInMilliseconds - the time period before the step has occurred; must be positive
        stepFunction - the function that determines if the step time has elapsed; may not be null
        postStepDelayInMilliseconds - the time period before the step has occurred; must be positive
        Returns:
        the strategy; never null
      • linear

        static ElapsedTimeStrategy linear​(Clock clock,
                                          long delayInMilliseconds)
        Create a strategy whose time periods linearly increase in length.
        Parameters:
        clock - the clock used to determine if sufficient time has elapsed; may not be null
        delayInMilliseconds - the initial delay; must be positive
        Returns:
        the strategy; never null
      • exponential

        static ElapsedTimeStrategy exponential​(Clock clock,
                                               long initialDelayInMilliseconds,
                                               long maxDelayInMilliseconds)
        Create a strategy whose time periods increase exponentially.
        Parameters:
        clock - the clock used to determine if sufficient time has elapsed; may not be null
        initialDelayInMilliseconds - the initial delay; must be positive
        maxDelayInMilliseconds - the maximum delay; must be greater than the initial delay
        Returns:
        the strategy; never null
      • exponential

        static ElapsedTimeStrategy exponential​(Clock clock,
                                               long initialDelayInMilliseconds,
                                               long maxDelayInMilliseconds,
                                               double multiplier)
        Create a strategy whose time periods increase exponentially.
        Parameters:
        clock - the clock used to determine if sufficient time has elapsed; may not be null
        initialDelayInMilliseconds - the initial delay; must be positive
        maxDelayInMilliseconds - the maximum delay; must be greater than the initial delay
        multiplier - the factor by which the delay increases each pass
        Returns:
        the strategy