Class TimeStableValidator

java.lang.Object
xbot.common.logic.TimeStableValidator

public class TimeStableValidator extends Object
Checks that a value is stable for a given amount of time.
  • Constructor Summary

    Constructors
    Constructor
    Description
    TimeStableValidator(double stableWindow)
    Creates a new TimeStableValidator using a constant value.
    TimeStableValidator(Supplier<Double> stableWindowProvider)
    Creates a new TimeStableValidator using a window from a supplier.
  • Method Summary

    Modifier and Type
    Method
    Description
    boolean
    checkStable(boolean value)
    Checks if the value has been stable for the entire stable window duration.
    boolean
    Checks if the value has been stable for the entire stable window duration, but without updating the internal state of the validator.
    void
    Used if you want the validator to start in a stable state.
    void
    setStableWindow(double stableWindow)
    Update the stable window using a constant value.
    void
    setStableWindowProvider(Supplier<Double> stableWindowProvider)
    Update the stable window using a supplier.

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TimeStableValidator

      public TimeStableValidator(double stableWindow)
      Creates a new TimeStableValidator using a constant value.
      Parameters:
      stableWindow - The time window, in seconds.
    • TimeStableValidator

      public TimeStableValidator(Supplier<Double> stableWindowProvider)
      Creates a new TimeStableValidator using a window from a supplier.
      Parameters:
      stableWindowProvider - A supplier that provides a time window, in seconds.
  • Method Details

    • setStableWindowProvider

      public void setStableWindowProvider(Supplier<Double> stableWindowProvider)
      Update the stable window using a supplier.
      Parameters:
      stableWindowProvider - A supplier that provides a time window, in seconds.
    • setStableWindow

      public void setStableWindow(double stableWindow)
      Update the stable window using a constant value.
      Parameters:
      stableWindow - The time window, in seconds.
    • checkStable

      public boolean checkStable(boolean value)
      Checks if the value has been stable for the entire stable window duration.
      Parameters:
      value - The value to test.
      Returns:
      True if the value has been stable for the entire window duration.
    • peekStable

      public boolean peekStable()
      Checks if the value has been stable for the entire stable window duration, but without updating the internal state of the validator. (Example usage: the validator is updated in a regular periodic call, but there are many listeners who are interested in the result.)
      Returns:
      True if the last checkStable() call returned true.
    • setStable

      public void setStable()
      Used if you want the validator to start in a stable state.