org.speakright.core.flows
Class LoopFlow

java.lang.Object
  extended by org.speakright.core.FlowBase
      extended by org.speakright.core.flows.BasicFlow
          extended by org.speakright.core.flows.LoopFlow
All Implemented Interfaces:
java.io.Serializable, IFlow

public class LoopFlow
extends BasicFlow

Represents looping behaviour. The given set of sub-flow objects will be executed numIterations times. Callflows often repeat things several times (three login attempts then fail), or infinitely (such as a main menu).

Author:
IanRaeLaptop
See Also:
Serialized Form

Field Summary
static int FOREVER
           
 
Fields inherited from class org.speakright.core.flows.BasicFlow
m_L
 
Constructor Summary
LoopFlow()
          Create a loop that loops forever (unless you change this using setNumIterations
LoopFlow(int numIterations)
          Create a loop that iterates the given number of times.
 
Method Summary
 void add(IFlow flow)
          add a sub-flow.
 IFlow getFirst(IFlowContext context)
          If there are sub-flows then return the first one, otherwise return self.
 IFlow getNext(IFlow current, SRResults results)
          Get the next sub-flow.
 IFlow getSubFlowAfter(IFlow subFlow)
          Return the next sub-flow after subFlow.
 int numIterations()
          Get the number of times this loop will iterate.
 void setNumIterations(int numIterations)
          Set (or change) the number of iterations.
 
Methods inherited from class org.speakright.core.flows.BasicFlow
addPromptFlow, findSubFlow, SubFlowCount
 
Methods inherited from class org.speakright.core.FlowBase
createRenderer, execute, executionCount, fixupGrammar, fixupPrompt, log, logError, name, onBegin, onCatch, onComplete, onDisconnect, onEnd, onNoInput, onPlatformError, onTransferFailed, onValidateFailed, promptGroup, setExecutionCount, setName, setPromptGroup, shouldExecute, validateInput
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

FOREVER

public static final int FOREVER
See Also:
Constant Field Values
Constructor Detail

LoopFlow

public LoopFlow()
Create a loop that loops forever (unless you change this using setNumIterations


LoopFlow

public LoopFlow(int numIterations)
Create a loop that iterates the given number of times.

Parameters:
numIterations -
Method Detail

numIterations

public int numIterations()
Get the number of times this loop will iterate.

Returns:

setNumIterations

public void setNumIterations(int numIterations)
Set (or change) the number of iterations. Can be called at any time, even after the loop has started.

Parameters:
numIterations -

add

public void add(IFlow flow)
Description copied from class: BasicFlow
add a sub-flow. Sub-flows will be executed in the order they were added.

Overrides:
add in class BasicFlow

getFirst

public IFlow getFirst(IFlowContext context)
Description copied from class: BasicFlow
If there are sub-flows then return the first one, otherwise return self. BasicFlow supports optional sub-flows. An optional sub-flow can return null from it's getFirst method to indicate that it doesn't wish to run. BasicFlow must still adhere to the rule that SRRunner requires getFirst never return null; therefore at least one sub-flow's getFirst must return non-null. Detail: getFirst method of sub-flows may be called more than once.

Specified by:
getFirst in interface IFlow
Overrides:
getFirst in class BasicFlow
Returns:
an IFlow object to be executed.

getSubFlowAfter

public IFlow getSubFlowAfter(IFlow subFlow)
Description copied from interface: IFlow
Return the next sub-flow after subFlow. Return null if subFlow is not one of our sub-flows, or there is no next one after it. This method is used to implement optional sub-flows (see BasicFlow)

Specified by:
getSubFlowAfter in interface IFlow
Overrides:
getSubFlowAfter in class BasicFlow
Returns:
null or next sub-flow after subFlow

getNext

public IFlow getNext(IFlow current,
                     SRResults results)
Get the next sub-flow. If we're at the last sub-flow then iterate again by returning the first sub-flow. If we're at the last sub-flow and have done the required number of iterations then return null.

Specified by:
getNext in interface IFlow
Overrides:
getNext in class BasicFlow
Parameters:
current - the currently executing flow object. More precisely, current is the flow object that this object most recently returned from getFirst or getNext.
results - the results of current's execution by the speech platform. Results contains user input and/or events such as disconnect or platform-error.
Returns:
the next flow to run, or null which means this flow object is finished.