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 classIfThenElse.IfThenElseDirectorA specialized director for an AbstractIfThenElse control actor.
-
Field Summary
Fields Modifier and Type Field Description static StringBACKUP_INPUTthe key for storing the current input token in the backup.protected BooleanConditionm_Conditionthe condition used for determining to execute then/else branch.protected Actorm_ElseActorthe actor to execute in the "else" branch.protected Tokenm_InputTokenthe input token.protected Actorm_ThenActorthe actor to execute in the "then" branch.static StringNAME_ELSEthe name of the "else" actor.static StringNAME_THENthe 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.StringconditionTipText()Returns the tip text for this property.TokencurrentInput()Returns the current input token, if any.voiddefineOptions()Adds options to the internal list of options.StringelseActorTipText()Returns the tip text for this property.Actorget(int index)Returns the actor at the given position.ActorHandlerInfogetActorHandlerInfo()Returns some information about the actor handler, e.g., whether it can contain standalones and the actor execution.BooleanConditiongetCondition()Returns the current condition.protected BooleanConditiongetDefaultCondition()Returns the default condition.protected ActorgetDefaultElse()Returns the default 'Else' actor.protected ActorgetDefaultThen()Returns the default 'Then' actor.ActorgetElseActor()Returns the actor of the 'else' branch.StringgetFixedName(int index)Returns the name for the sub-actor at this position.StringgetQuickInfo()Returns a quick info about the actor, which will be displayed in the GUI.ActorgetThenActor()Returns the actor of the 'then' branch.StringglobalInfo()Returns a string describing the object.booleanhasInput()Returns whether an input token is currently present.intindexOf(String actor)Returns the index of the actor.protected voidinitialize()Initializes the members.voidinput(Token token)The method that accepts the input token and then processes it.protected AbstractDirectornewDirector()Returns an instance of a director.protected StringpostExecute()Post-execute hook.protected voidrestoreState(Hashtable<String,Object> state)Restores the state of the actor before the variables got updated.Stringset(int index, Actor actor)Sets the actor at the given position.voidsetCondition(BooleanCondition value)Sets the condition.voidsetElseActor(Actor value)Sets the actor of the 'else' branch.voidsetThenActor(Actor value)Sets the actor of the 'then' branch.StringsetUp()Initializes the sub-actors for flow execution.intsize()Returns the size of the group.voidstopExecution()Stops the execution.StringthenActorTipText()Returns the tip text for this property.voidwrapUp()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:
globalInfoin interfaceGlobalInfoSupporter- Specified by:
globalInfoin classAbstractOptionHandler- Returns:
- a description suitable for displaying in the gui
-
defineOptions
public void defineOptions()
Adds options to the internal list of options.- Specified by:
defineOptionsin interfaceOptionHandler- Overrides:
defineOptionsin classAbstractDirectedControlActor
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initializein classAbstractControlActor
-
getQuickInfo
public String getQuickInfo()
Returns a quick info about the actor, which will be displayed in the GUI.- Specified by:
getQuickInfoin interfaceActor- Specified by:
getQuickInfoin interfaceQuickInfoSupporter- Overrides:
getQuickInfoin 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:
newDirectorin classAbstractDirectedControlActor- Returns:
- the director
-
setCondition
public void setCondition(BooleanCondition value)
Sets the condition.- Specified by:
setConditionin interfaceBooleanConditionSupporter- Parameters:
value- the condition
-
getCondition
public BooleanCondition getCondition()
Returns the current condition.- Specified by:
getConditionin 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:
sizein interfaceActorHandler- Specified by:
sizein classAbstractControlActor- Returns:
- always 2
-
get
public Actor get(int index)
Returns the actor at the given position.- Specified by:
getin interfaceActorHandler- Specified by:
getin 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:
setin interfaceActorHandler- Specified by:
setin 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:
indexOfin interfaceActorHandler- Specified by:
indexOfin 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:
getActorHandlerInfoin interfaceActorHandler- Specified by:
getActorHandlerInfoin classAbstractControlActor- Returns:
- the info
-
getFixedName
public String getFixedName(int index)
Returns the name for the sub-actor at this position.- Specified by:
getFixedNamein 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:
acceptsin 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:
backupStatein 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:
restoreStatein 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:
setUpin interfaceActor- Overrides:
setUpin 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:
inputin interfaceInputConsumer- Parameters:
token- the token to accept and process
-
hasInput
public boolean hasInput()
Returns whether an input token is currently present.- Specified by:
hasInputin interfaceInputConsumer- Returns:
- true if input token present
-
currentInput
public Token currentInput()
Returns the current input token, if any.- Specified by:
currentInputin interfaceInputConsumer- Returns:
- the input token, null if none present
-
postExecute
protected String postExecute()
Post-execute hook.- Overrides:
postExecutein 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:
wrapUpin interfaceActor- Overrides:
wrapUpin classAbstractDirectedControlActor
-
stopExecution
public void stopExecution()
Stops the execution.- Specified by:
stopExecutionin interfaceActor- Specified by:
stopExecutionin interfaceStoppable- Overrides:
stopExecutionin classAbstractDirectedControlActor
-
-