Package adams.flow.control
Class IfThenElse
-
- All Implemented Interfaces:
AdditionalInformationHandler
,CleanUpHandler
,Destroyable
,GlobalInfoSupporter
,LoggingLevelHandler
,LoggingSupporter
,OptionHandler
,Pausable
,QuickInfoSupporter
,ShallowCopySupporter<Actor>
,SizeOfHandler
,Stoppable
,StoppableWithFeedback
,VariablesInspectionHandler
,FlowPauseStateListener
,VariableChangeListener
,BooleanConditionSupporter
,AtomicExecution
,Actor
,ActorHandler
,ControlActor
,ErrorHandler
,FixedNameActorHandler
,Flushable
,InputConsumer
,SubFlowWrapUp
,Serializable
,Comparable
public class IfThenElse extends AbstractDirectedControlActor implements InputConsumer, FixedNameActorHandler, BooleanConditionSupporter
Emulates an If-Then-Else construct. The 'Then' branch gets executed if the 'If' condition evaluates to 'true', otherwise the 'else' branch gets executed.
Valid options are:
-D <int> (property: debugLevel) The greater the number the more additional info the scheme may output to the console (0 = off). default: 0 minimum: 0
-name <java.lang.String> (property: name) The name of the actor. default: IfThenElse
-annotation <adams.core.base.BaseText> (property: annotations) The annotations to attach to this actor. default:
-skip (property: skip) If set to true, transformation is skipped and the input token is just forwarded as it is.
-stop-flow-on-error (property: stopFlowOnError) If set to true, the flow gets stopped in case this actor encounters an error; useful for critical actors.
-condition <adams.flow.condition.AbstractIfThenElseCondition> (property: condition) The condition that determines which branch to execute: if it evaluates to 'true' then the 'then' branch gets executed. default: adams.flow.condition.Expression
-then <adams.flow.core.Actor> (property: thenActor) The actor of the 'then' branch. default: adams.flow.control.Sequence -name then
-else <adams.flow.core.Actor> (property: elseActor) The actor of the 'else' branch. default: adams.flow.control.Sequence -name else
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
IfThenElse.IfThenElseDirector
A specialized director for an AbstractIfThenElse control actor.
-
Field Summary
Fields Modifier and Type Field Description static String
BACKUP_INPUT
the key for storing the current input token in the backup.protected BooleanCondition
m_Condition
the condition used for determining to execute then/else branch.protected Actor
m_ElseActor
the actor to execute in the "else" branch.protected Token
m_InputToken
the input token.protected Actor
m_ThenActor
the actor to execute in the "then" branch.static String
NAME_ELSE
the name of the "else" actor.static String
NAME_THEN
the name of the "then" actor.-
Fields inherited from class adams.flow.control.AbstractDirectedControlActor
m_Director, m_FinishBeforeStopping, m_StoppingTimeout, m_StoppingWarningInterval
-
Fields inherited from class adams.flow.control.AbstractControlActor
m_Compatibility, m_PauseStateManager, m_SetUpSubActors
-
Fields inherited from class adams.flow.core.AbstractActor
m_Annotations, m_BackupState, m_DetectedObjectVariables, m_DetectedVariables, m_ErrorHandler, m_Executed, m_Executing, m_ExecutionListeningSupporter, m_FullName, m_LoggingPrefix, m_Name, m_Parent, m_ScopeHandler, m_Self, m_Silent, m_Skip, m_StopFlowOnError, m_StopMessage, m_Stopped, m_StorageHandler, m_VariablesUpdated
-
Fields inherited from class adams.core.option.AbstractOptionHandler
m_OptionManager
-
Fields inherited from class adams.core.logging.LoggingObject
m_Logger, m_LoggingIsEnabled, m_LoggingLevel
-
Fields inherited from interface adams.flow.core.Actor
FILE_EXTENSION, FILE_EXTENSION_GZ
-
-
Constructor Summary
Constructors Constructor Description IfThenElse()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Class[]
accepts()
Returns the class that the condition accepts.protected Hashtable<String,Object>
backupState()
Backs up the current state of the actor before update the variables.String
conditionTipText()
Returns the tip text for this property.Token
currentInput()
Returns the current input token, if any.void
defineOptions()
Adds options to the internal list of options.String
elseActorTipText()
Returns the tip text for this property.Actor
get(int index)
Returns the actor at the given position.ActorHandlerInfo
getActorHandlerInfo()
Returns some information about the actor handler, e.g., whether it can contain standalones and the actor execution.BooleanCondition
getCondition()
Returns the current condition.protected BooleanCondition
getDefaultCondition()
Returns the default condition.protected Actor
getDefaultElse()
Returns the default 'Else' actor.protected Actor
getDefaultThen()
Returns the default 'Then' actor.Actor
getElseActor()
Returns the actor of the 'else' branch.String
getFixedName(int index)
Returns the name for the sub-actor at this position.String
getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.Actor
getThenActor()
Returns the actor of the 'then' branch.String
globalInfo()
Returns a string describing the object.boolean
hasInput()
Returns whether an input token is currently present.int
indexOf(String actor)
Returns the index of the actor.protected void
initialize()
Initializes the members.void
input(Token token)
The method that accepts the input token and then processes it.protected AbstractDirector
newDirector()
Returns an instance of a director.protected String
postExecute()
Post-execute hook.protected void
restoreState(Hashtable<String,Object> state)
Restores the state of the actor before the variables got updated.String
set(int index, Actor actor)
Sets the actor at the given position.void
setCondition(BooleanCondition value)
Sets the condition.void
setElseActor(Actor value)
Sets the actor of the 'else' branch.void
setThenActor(Actor value)
Sets the actor of the 'then' branch.String
setUp()
Initializes the sub-actors for flow execution.int
size()
Returns the size of the group.void
stopExecution()
Stops the execution.String
thenActorTipText()
Returns the tip text for this property.void
wrapUp()
Cleans up after the execution has finished.-
Methods inherited from class adams.flow.control.AbstractDirectedControlActor
cleanUp, doExecute, finishBeforeStoppingTipText, flushExecution, getDirector, getFinishBeforeStopping, getStoppingTimeout, getStoppingWarningInterval, setFinishBeforeStopping, setStoppingTimeout, setStoppingWarningInterval, stoppingTimeoutTipText, stoppingWarningIntervalTipText, updateVariables
-
Methods inherited from class adams.flow.control.AbstractControlActor
active, canInspectOptions, check, destroy, firstActive, firstInputConsumer, flowPauseStateChanged, forceVariables, isPaused, isSubFlowWrappedUp, lastActive, pauseExecution, preExecute, reset, resumeExecution, setParent, setUpSubActors, updateParent, wrapUpSubFlow
-
Methods inherited from class adams.flow.core.AbstractActor
annotationsTipText, canPerformSetUpCheck, compareTo, configureLogger, equals, execute, finalUpdateVariables, findVariables, findVariables, forCommandLine, forName, forName, getAdditionalInformation, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowActors, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, handleException, hasErrorHandler, hasStopMessage, index, isBackedUp, isExecuted, isExecuting, isFinished, isHeadless, isStopped, nameTipText, performSetUpChecks, performVariableChecks, pruneBackup, pruneBackup, setAnnotations, setErrorHandler, setName, setSilent, setSkip, setStopFlowOnError, setVariables, shallowCopy, shallowCopy, silentTipText, sizeOf, skipTipText, stopExecution, stopFlowOnErrorTipText, updateDetectedVariables, updatePrefix, variableChanged
-
Methods inherited from class adams.core.option.AbstractOptionHandler
cleanUpOptions, finishInit, getDefaultLoggingLevel, getOptionManager, loggingLevelTipText, newOptionManager, setLoggingLevel, toCommandLine, toString
-
Methods inherited from class adams.core.logging.LoggingObject
getLogger, getLoggingLevel, initializeLogging, isLoggingEnabled
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface adams.flow.core.Actor
cleanUp, compareTo, destroy, equals, execute, findVariables, getAnnotations, getDefaultName, getDetectedVariables, getErrorHandler, getFlowExecutionListeningSupporter, getFullName, getName, getNextSibling, getParent, getParentComponent, getPreviousSibling, getRoot, getScopeHandler, getSilent, getSkip, getStopFlowOnError, getStopMessage, getStorageHandler, getVariables, handleError, hasErrorHandler, hasStopMessage, index, isExecuted, isFinished, isHeadless, isStopped, setAnnotations, setErrorHandler, setName, setParent, setSilent, setSkip, setStopFlowOnError, setVariables, shallowCopy, shallowCopy, sizeOf, stopExecution, toCommandLine, variableChanged
-
Methods inherited from interface adams.flow.core.ActorHandler
check, firstActive, flushExecution, lastActive
-
Methods inherited from interface adams.core.AdditionalInformationHandler
getAdditionalInformation
-
Methods inherited from interface adams.core.logging.LoggingLevelHandler
getLoggingLevel, setLoggingLevel
-
Methods inherited from interface adams.core.logging.LoggingSupporter
getLogger, isLoggingEnabled
-
Methods inherited from interface adams.core.option.OptionHandler
cleanUpOptions, getOptionManager
-
Methods inherited from interface adams.core.VariablesInspectionHandler
canInspectOptions
-
-
-
-
Field Detail
-
BACKUP_INPUT
public static final String BACKUP_INPUT
the key for storing the current input token in the backup.- See Also:
- Constant Field Values
-
NAME_THEN
public static final String NAME_THEN
the name of the "then" actor.- See Also:
- Constant Field Values
-
NAME_ELSE
public static final String NAME_ELSE
the name of the "else" actor.- See Also:
- Constant Field Values
-
m_Condition
protected BooleanCondition m_Condition
the condition used for determining to execute then/else branch.
-
m_ThenActor
protected Actor m_ThenActor
the actor to execute in the "then" branch.
-
m_ElseActor
protected Actor m_ElseActor
the actor to execute in the "else" branch.
-
m_InputToken
protected transient Token m_InputToken
the input token.
-
-
Method Detail
-
globalInfo
public String globalInfo()
Returns a string describing the object.- Specified by:
globalInfo
in interfaceGlobalInfoSupporter
- Specified by:
globalInfo
in classAbstractOptionHandler
- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptions
in interfaceOptionHandler
- Overrides:
defineOptions
in classAbstractDirectedControlActor
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classAbstractControlActor
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.- Specified by:
getQuickInfo
in interfaceActor
- Specified by:
getQuickInfo
in interfaceQuickInfoSupporter
- Overrides:
getQuickInfo
in classAbstractDirectedControlActor
- Returns:
- null if no info available, otherwise short string
-
getDefaultCondition
protected BooleanCondition getDefaultCondition()
Returns the default condition.- Returns:
- the default condition
-
getDefaultThen
protected Actor getDefaultThen()
Returns the default 'Then' actor.- Returns:
- the default actor
-
getDefaultElse
protected Actor getDefaultElse()
Returns the default 'Else' actor.- Returns:
- the default actor
-
newDirector
protected AbstractDirector newDirector()
Returns an instance of a director.- Overrides:
newDirector
in classAbstractDirectedControlActor
- Returns:
- the director
-
setCondition
public void setCondition(BooleanCondition value)
Sets the condition.- Specified by:
setCondition
in interfaceBooleanConditionSupporter
- Parameters:
value
- the condition
-
getCondition
public BooleanCondition getCondition()
Returns the current condition.- Specified by:
getCondition
in interfaceBooleanConditionSupporter
- Returns:
- the condition
-
conditionTipText
public String conditionTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setThenActor
public void setThenActor(Actor value)
Sets the actor of the 'then' branch.- Parameters:
value
- the actor
-
getThenActor
public Actor getThenActor()
Returns the actor of the 'then' branch.- Returns:
- the actor
-
thenActorTipText
public String thenActorTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
setElseActor
public void setElseActor(Actor value)
Sets the actor of the 'else' branch.- Parameters:
value
- the actor
-
getElseActor
public Actor getElseActor()
Returns the actor of the 'else' branch.- Returns:
- the actor
-
elseActorTipText
public String elseActorTipText()
Returns the tip text for this property.- Returns:
- tip text for this property suitable for displaying in the GUI or for listing the options.
-
size
public int size()
Returns the size of the group.- Specified by:
size
in interfaceActorHandler
- Specified by:
size
in classAbstractControlActor
- Returns:
- always 2
-
get
public Actor get(int index)
Returns the actor at the given position.- Specified by:
get
in interfaceActorHandler
- Specified by:
get
in classAbstractControlActor
- Parameters:
index
- the position- Returns:
- the actor
-
set
public String set(int index, Actor actor)
Sets the actor at the given position.- Specified by:
set
in interfaceActorHandler
- Specified by:
set
in classAbstractControlActor
- Parameters:
index
- the positionactor
- the actor to set at this position- Returns:
- null if everything is fine, otherwise the error
-
indexOf
public int indexOf(String actor)
Returns the index of the actor.- Specified by:
indexOf
in interfaceActorHandler
- Specified by:
indexOf
in classAbstractControlActor
- Parameters:
actor
- the name of the actor to look for- Returns:
- the index of -1 if not found
-
getActorHandlerInfo
public ActorHandlerInfo getActorHandlerInfo()
Returns some information about the actor handler, e.g., whether it can contain standalones and the actor execution.- Specified by:
getActorHandlerInfo
in interfaceActorHandler
- Specified by:
getActorHandlerInfo
in classAbstractControlActor
- Returns:
- the info
-
getFixedName
public String getFixedName(int index)
Returns the name for the sub-actor at this position.- Specified by:
getFixedName
in interfaceFixedNameActorHandler
- Parameters:
index
- the position of the sub-actor- Returns:
- the name to use
-
accepts
public Class[] accepts()
Returns the class that the condition accepts.- Specified by:
accepts
in interfaceInputConsumer
- Returns:
- what the condition accepts
-
backupState
protected Hashtable<String,Object> backupState()
Backs up the current state of the actor before update the variables.- Overrides:
backupState
in classAbstractActor
- Returns:
- the backup
- See Also:
AbstractActor.updateVariables()
,AbstractActor.restoreState(Hashtable)
-
restoreState
protected void restoreState(Hashtable<String,Object> state)
Restores the state of the actor before the variables got updated.- Overrides:
restoreState
in classAbstractActor
- Parameters:
state
- the backup of the state to restore from- See Also:
AbstractActor.updateVariables()
,AbstractActor.backupState()
-
setUp
public String setUp()
Initializes the sub-actors for flow execution.- Specified by:
setUp
in interfaceActor
- Overrides:
setUp
in classAbstractDirectedControlActor
- Returns:
- null if everything is fine, otherwise error message
- See Also:
AbstractActor.reset()
-
input
public void input(Token token)
The method that accepts the input token and then processes it.- Specified by:
input
in interfaceInputConsumer
- Parameters:
token
- the token to accept and process
-
hasInput
public boolean hasInput()
Returns whether an input token is currently present.- Specified by:
hasInput
in interfaceInputConsumer
- Returns:
- true if input token present
-
currentInput
public Token currentInput()
Returns the current input token, if any.- Specified by:
currentInput
in interfaceInputConsumer
- Returns:
- the input token, null if none present
-
postExecute
protected String postExecute()
Post-execute hook.- Overrides:
postExecute
in classAbstractActor
- Returns:
- null if everything is fine, otherwise error message
- See Also:
AbstractActor.m_Executed
-
wrapUp
public void wrapUp()
Cleans up after the execution has finished. Graphical output is left untouched.- Specified by:
wrapUp
in interfaceActor
- Overrides:
wrapUp
in classAbstractDirectedControlActor
-
stopExecution
public void stopExecution()
Stops the execution.- Specified by:
stopExecution
in interfaceActor
- Specified by:
stopExecution
in interfaceStoppable
- Overrides:
stopExecution
in classAbstractDirectedControlActor
-
-