Package jasima.core.simulation.generic
Class ConditionQueue
- java.lang.Object
-
- jasima.core.simulation.generic.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 anObservableValue(which can be a plain value or a @linkDerivedObservable).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 Summary
Constructors Constructor Description ConditionQueue(ObservableValue<Boolean> condition)Create a new condition queue based on the value of onObservableValue(this can also be aDerivedObservable).ConditionQueue(Supplier<Boolean> boolExpression, ObservableValue<?>... exprDependencies)Creates a new condition queue depending on a certain condition.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanexecuteWhenTrue(Runnable action)Executes theRunnableprovided as a parameter exactly once when the condition becomes true.intnumActions()Returns the number of actions currently waiting on the condition.
-
-
-
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 aDerivedObservableto get notifications whenever the condition is changing.- Parameters:
boolExpression- A boolean expression containing otherObservableValues.exprDependencies- AllObservableValues used in the expression.
-
ConditionQueue
public ConditionQueue(ObservableValue<Boolean> condition)
Create a new condition queue based on the value of onObservableValue(this can also be aDerivedObservable).- Parameters:
condition- The observable value of type boolean to use in order to perform actions.
-
-
Method Detail
-
executeWhenTrue
public boolean executeWhenTrue(Runnable action)
Executes theRunnableprovided 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. Otherwisefalsewill be returned and 'action' will be stored in an internal list to be executed when the condition becomestrue.- 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.
-
-