Class ConditionalAction
java.lang.Object
neqsim.process.logic.action.ConditionalAction
- All Implemented Interfaces:
LogicAction
Executes an action conditionally based on a runtime condition.
Conditional actions provide if-then-else logic within process sequences:
- If condition is true, execute primary action
- If condition is false, execute alternative action (optional)
- Enables dynamic decision-making in sequences
Example usage:
// If temperature > 100°C, open cooling valve; else open bypass valve
LogicCondition highTemp = new TemperatureCondition(reactor, 100.0, ">");
LogicAction openCooling = new OpenValveAction(coolingValve);
LogicAction openBypass = new OpenValveAction(bypassValve);
ConditionalAction conditional =
new ConditionalAction(highTemp, openCooling, openBypass, "Temperature Control");
// In sequence
startupLogic.addAction(conditional, 0.0);
// Execute - checks condition at runtime
conditional.execute(); // Opens appropriate valve based on current temperature
- Version:
- 1.0
- Author:
- ESOL
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final LogicActionprivate final LogicConditionprivate final Stringprivate booleanprivate final LogicActionprivate LogicAction -
Constructor Summary
ConstructorsConstructorDescriptionConditionalAction(LogicCondition condition, LogicAction primaryAction, String description) Creates a conditional action with primary action only (no alternative).ConditionalAction(LogicCondition condition, LogicAction primaryAction, LogicAction alternativeAction, String description) Creates a conditional action with both primary and alternative actions. -
Method Summary
Modifier and TypeMethodDescriptionvoidexecute()Executes the action.Gets the alternative action (executed if condition false).Gets the condition being evaluated.Gets a human-readable description of the action.Gets the primary action (executed if condition true).Gets the action that was selected after evaluation.Gets the name of the target equipment.booleanChecks if the action has completed.booleanChecks if the condition has been evaluated.voidreset()Resets the conditional for re-evaluation.
-
Field Details
-
condition
-
-
alternativeAction
-
description
-
evaluated
private boolean evaluated -
selectedAction
-
-
Constructor Details
-
ConditionalAction
Creates a conditional action with primary action only (no alternative).- Parameters:
condition- condition to evaluateprimaryAction- action to execute if condition is truedescription- description of this conditional
-
ConditionalAction
public ConditionalAction(LogicCondition condition, LogicAction primaryAction, LogicAction alternativeAction, String description) Creates a conditional action with both primary and alternative actions.- Parameters:
condition- condition to evaluateprimaryAction- action to execute if condition is truealternativeAction- action to execute if condition is false (can be null)description- description of this conditional
-
-
Method Details
-
execute
public void execute()Description copied from interface:LogicActionExecutes the action.This method performs the actual operation on the target equipment.
- Specified by:
executein interfaceLogicAction
-
isComplete
public boolean isComplete()Description copied from interface:LogicActionChecks if the action has completed.Some actions are instantaneous (return true immediately), while others may take time to complete (e.g., valve stroke).
- Specified by:
isCompletein interfaceLogicAction- Returns:
- true if action is complete
-
getDescription
Description copied from interface:LogicActionGets a human-readable description of the action.- Specified by:
getDescriptionin interfaceLogicAction- Returns:
- action description
-
getTargetName
Description copied from interface:LogicActionGets the name of the target equipment.- Specified by:
getTargetNamein interfaceLogicAction- Returns:
- equipment name
-
getCondition
-
getPrimaryAction
Gets the primary action (executed if condition true).- Returns:
- primary action
-
getAlternativeAction
Gets the alternative action (executed if condition false).- Returns:
- alternative action, or null if none
-
getSelectedAction
Gets the action that was selected after evaluation.- Returns:
- selected action, or null if not yet evaluated
-
isEvaluated
public boolean isEvaluated()Checks if the condition has been evaluated.- Returns:
- true if evaluated
-
reset
public void reset()Resets the conditional for re-evaluation.
-