Class ConditionQueue


  • public class ConditionQueue
    extends Object
    This class allows basing the execution of certain actions on some condition to, e.g., create a holdUntil/waitUntil statement in a simulation model. Condition queues can be constructed by either specifying a boolean expression (and its immediate dependencies) or directly by an ObservableValue (which can be a plain value or a @link DerivedObservable).

    Once created, the method executeWhenTrue(Runnable) can be used to run some code when the condition becomes true.

    Author:
    Torsten Hildebrandt
    See Also:
    ObservableValue
    • Constructor Detail

      • ConditionQueue

        public ConditionQueue​(Supplier<Boolean> boolExpression,
                              ObservableValue<?>... exprDependencies)
        Creates a new condition queue depending on a certain condition. Internally the parameters to this constructor are used to create a DerivedObservable to get notifications whenever the condition is changing.
        Parameters:
        boolExpression - A boolean expression containing other ObservableValues.
        exprDependencies - All ObservableValues used in the expression.
      • ConditionQueue

        public ConditionQueue​(ObservableValue<Boolean> condition)
        Create a new condition queue based on the value of on ObservableValue (this can also be a DerivedObservable).
        Parameters:
        condition - The observable value of type boolean to use in order to perform actions.
    • Method Detail

      • executeWhenTrue

        public boolean executeWhenTrue​(Runnable action)
        Executes the Runnable provided as a parameter exactly once when the condition becomes true. If the condition is already true when this method is called, then 'action' is run immediately and true will be returned. Otherwise false will be returned and 'action' will be stored in an internal list to be executed when the condition becomes true.
        Parameters:
        action - The action to run. Mustn't be null.
        Returns:
        The value of the condition when this method is executed.
      • numActions

        public int numActions()
        Returns the number of actions currently waiting on the condition.