Class IterativePollInterval

  • All Implemented Interfaces:
    PollInterval

    public class IterativePollInterval
    extends java.lang.Object
    implements PollInterval
    A poll interval that is generated by a function and a start duration. The function is free to do anything with the duration. For example:
     await().with().pollInterval(iterative(duration -> duration.multiply(2)), Duration.FIVE_HUNDRED_MILLISECONDS).until(..);
     
    This generates a poll interval sequence that looks like this (ms): 500, 1000, 2000, 4000, 8000, 16000, ...

    Note that if the user specifies a poll delay this delay will take place before the first call to next(int, Duration).

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private java.util.function.Function<java.time.Duration,​java.time.Duration> function  
      private java.time.Duration startDuration  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
        IterativePollInterval​(java.util.function.Function<java.time.Duration,​java.time.Duration> function)
      Generate an iterative poll interval based on the supplied function.
        IterativePollInterval​(java.util.function.Function<java.time.Duration,​java.time.Duration> function, java.time.Duration startDuration)
      Generate a iterative poll interval based on the supplied function and start duration.
      private IterativePollInterval​(java.util.function.Function<java.time.Duration,​java.time.Duration> function, java.time.Duration startDuration, boolean startDurationExplicitlyDefined)
      Generate a iterative poll interval based on the supplied function and start duration.
    • Field Detail

      • function

        private final java.util.function.Function<java.time.Duration,​java.time.Duration> function
      • startDuration

        private final java.time.Duration startDuration
    • Constructor Detail

      • IterativePollInterval

        public IterativePollInterval​(java.util.function.Function<java.time.Duration,​java.time.Duration> function)
        Generate an iterative poll interval based on the supplied function.
        Parameters:
        function - The function to use.
      • IterativePollInterval

        public IterativePollInterval​(java.util.function.Function<java.time.Duration,​java.time.Duration> function,
                                     java.time.Duration startDuration)
        Generate a iterative poll interval based on the supplied function and start duration.
        Parameters:
        function - The function to use.
        startDuration - The start duration (initial function value)
      • IterativePollInterval

        private IterativePollInterval​(java.util.function.Function<java.time.Duration,​java.time.Duration> function,
                                      java.time.Duration startDuration,
                                      boolean startDurationExplicitlyDefined)
        Generate a iterative poll interval based on the supplied function and start duration.
        Parameters:
        function - The function to use.
        startDuration - The start duration (initial function value)
    • Method Detail

      • next

        public java.time.Duration next​(int pollCount,
                                       java.time.Duration previousDuration)
        Generate the next Duration based on the supplied function. If you've specified a start duration explicitly then this start duration will override the value of previousDuration when pollCount is 1 (i.e. the poll delay).
        Specified by:
        next in interface PollInterval
        Parameters:
        pollCount - The number of times the condition has been polled (evaluated). Always a positive integer.
        previousDuration - The duration of the previously returned poll interval.
        Returns:
        The duration of the next poll interval
      • iterative

        public static IterativePollInterval iterative​(java.util.function.Function<java.time.Duration,​java.time.Duration> function,
                                                      java.time.Duration startDuration)
        Syntactic sugar for creating a IterativePollInterval.
        Parameters:
        function - The function to use
        startDuration - The start duration (initial function value)
        Returns:
        A new instance of IterativePollInterval
      • startDuration

        public IterativePollInterval startDuration​(java.time.Duration duration)
        Set the start duration of this poll interval
        Returns:
        A new of instance of IterativePollInterval with the given start duration
      • equals

        public boolean equals​(java.lang.Object o)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object