Package xbot.common.logic
Class TimeStableValidator
java.lang.Object
xbot.common.logic.TimeStableValidator
Checks that a value is stable for a given amount of time.
-
Constructor Summary
ConstructorDescriptionTimeStableValidator
(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 TypeMethodDescriptionboolean
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.
-
Constructor Details
-
TimeStableValidator
public TimeStableValidator(double stableWindow) Creates a new TimeStableValidator using a constant value.- Parameters:
stableWindow
- The time window, in seconds.
-
TimeStableValidator
Creates a new TimeStableValidator using a window from a supplier.- Parameters:
stableWindowProvider
- A supplier that provides a time window, in seconds.
-
-
Method Details
-
setStableWindowProvider
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.
-