Class IterativeProcess<T>

  • Type Parameters:
    T - the type that represents the step
    All Implemented Interfaces:
    ObservableIfc, IterativeProcessIfc, GetNameIfc
    Direct Known Subclasses:
    Executive.EventExecutionProcess, IPRootFinder, Simulation.ReplicationExecutionProcess

    public abstract class IterativeProcess<T>
    extends java.lang.Object
    implements ObservableIfc, IterativeProcessIfc
    A IterativeProcess is an abstract base class for modeling the execution of a series of steps until some condition is met or until the number of steps have been exhausted. An iterative process will stop when one of the following occurs: a) It has no more steps to execute b) A condition becomes true after a step i) A user supplied (real) time limit has been (approximately) reached ii) Calling the stop() method based on some condition iii) Calling end() when in state Created, Initialized, or StepCompleted An iterative process follows a well defined state transition pattern. An iterative process has the following states: (Created, Initialized, StepCompleted, Ended). An iterative process is first created and placed in the Created state. From the Created state it can transition to Initialized (via initialize()) or Ended (via end()). From the Ended state it can transition to Initialized (via initialize()). From the Initialized state it can transition to StepCompleted (via runNext()) or to Ended (via run() or end()). From the StepCompleted state it can transition back to StepCompleted (via runNext()) or to Ended (via run(), runNext(), or end()). Thus, a common usage of an IterativeProcess is to call initialize() after construction and call runNext() to run each step of the process as needed. An IterativeProcess can also run to completion by calling run(). Subclasses must provide the following abstract protected methods: boolean hasNext(): checks if there is a next step T next(): gets an object that represents the next step void runStep(): causes the next step to execute, if no step exists then a run time exception, NoSuchStepException, will be thrown. If a client attempts an illegal state transition, then a run time exception, IllegalStateException, will be thrown. Sub-classes should also consider overriding initializeIterations() and endIterations() to provide specific initialization logic and logic for after the process ends. When overriding these methods care should be taken to properly call super.initializeIterations() and super.endIterations() otherwise non-determinant behavior will occur. The pattern is general enough to allow IterativeProcesses to run other IterativeProcesses within each step.
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static int COMPLETED_ALL_STEPS
      Indicates whether the iterative process has completed running all steps
      protected java.lang.String COMPLETED_ALL_STEPS_MSG
      Message used when process completes all steps
      static int EXCEEDED_EXECUTION_TIME
      Indicates whether the iterative process has exceeded its maximum execution time
      protected java.lang.String EXCEEDED_EXECUTION_TIME_MSG
      Message used when process exceeds its execution time
      static int MET_STOPPING_CONDITION
      Indicates whether the iterative process ended due to the being stopped
      protected java.lang.String MET_STOPPING_CONDITION_MSG
      Message used when process stops because it met a condition
      protected long myBeginExecutionTime
      The wall clock time in milliseconds that the iterative process started
      protected IterativeProcess.Created myCreatedState
      A reference to the created state for the iterative process A iterative process is in the created state when it is first constructed and can then only transition to the initialized state
      protected T myCurrentStep
      A reference to an object related to the current step of the process It can be passed to observers
      protected boolean myDoneFlag
      A flag to indicate whether the iterative process is done A iterative process can be done if: 1) it ran all of its steps 2) it was canceled by a client prior to completing all of its steps 3) it exceeded its maximum allowable execution time before completing all of its steps.
      protected IterativeProcess.Ended myEndedState
      A reference to the ended state of the iterative process A iterative process is in the ended state after the process is told to end
      protected long myEndExecutionTime
      The wall clock time in milliseconds that the iterative process ended
      protected int myEndingStateIndicator
      indicates how the iterative process ended
      protected long myId
      The id of this object
      protected boolean myInitFlag
      A flag that indicates whether or not the iterative process has already been initialized, false means it has not been initialized, true means that it has been initialized
      protected IterativeProcess.Initialized myInitializedState
      A reference to the initialized state of the iterative process A iterative process is in the initialized state after the initialize() method is called from a proper state.
      protected IPLogReport myIPLogReport
      Used to log state changes
      protected long myMaxAllowedExecutionTime
      The maximum allowable execution time "wall" clock time for the iterative process to complete processing in milliseconds
      protected java.lang.String myName
      The name of this step
      protected ObservableComponent myObservableComponent
      Allows the IterativeProcess to be observable.
      protected boolean myRunningFlag
      Indicates that the iterative process is running
      protected boolean myRunningStepFlag
      Indicates if the iterative process is currently running an individual step, true if the step is in progress
      protected boolean mySaveStepOption
      A flag to indicate whether or not the iterative process will save the steps as they are created and then run in a Collection The default is FALSE (they will be not be saved).
      protected IterativeProcess.IterativeState myState
      A reference to the current state of the iterative process
      protected IterativeProcess.StepCompleted myStepCompletedState
      A reference to the step completed state of the iterative process A iterative process is in the step completed state after the runNext method is called from a proper state
      protected long myStepCounter
      Counts the number of steps executed since the last time the process was initialized
      protected java.util.List<T> mySteps
      A collection of all the steps that have been run by this iterative process.
      protected long myTBConsoleUpdates
      The time between task invocations for the Timer and its TimerTask
      protected java.util.Timer myTimer
      A Timer used to perform timed task e.g.
      protected java.util.TimerTask myTimerTask
      The task that the timer uses
      static int NO_STEPS_EXECUTED
      Indicates whether the iterative process haD no steps to run
      protected java.lang.String NO_STEPS_EXECUTED_MSG
      Message used when process completes all steps
      static int UNFINISHED
      Indicates that the iterative process is in progress
      protected java.lang.String UNFINISHED_MSG
      Message used when process is not finished
    • Constructor Summary

      Constructors 
      Constructor Description
      IterativeProcess()
      Constructs an iterative process with default name
      IterativeProcess​(java.lang.String name)
      Constructs an iterative process with the given name
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      void addObserver​(ObserverIfc observer)
      Allows the adding (attaching) of an observer to the observable
      boolean allStepsCompleted()
      The iterative process may end by a variety of means, this method checks if the iterative process ended because it ran all of its steps
      protected void checkStoppingCondition()  
      protected void checkStoppingCondition_()  
      protected void consoleOutput()
      Can be overwritten by subclasses to have output when the console flag is on
      boolean contains​(ObserverIfc observer)
      Returns true if the observer is already attached
      int countObservers()
      Returns how many observers are currently observing the observable
      void deleteObserver​(ObserverIfc observer)
      Allows the deletion (removing) of an observer from the observable
      void deleteObservers()
      Deletes all the observers from the observable
      void end()
      The iterative process will continue until there are no more steps or its maximum execution time has been reached, whichever comes first.
      void end​(java.lang.String msg)
      The iterative process will continue until there are no more steps or its maximum execution time has been reached, whichever comes first.
      protected void endIterations()  
      boolean executionTimeExceeded()
      The iterative process may end by a variety of means, this method checks if the iterative process ended because it timed out
      long getBeginExecutionTime()
      Returns system time in milliseconds that the iterative process started
      java.lang.String getCurrentStateAsString()
      Gets the current state as a string
      T getCurrentStep()
      Returns the current step for the iterative process the step that is or has just completed processing Note: Sub-classes are responsible for properly setting the current step when a step is run via runStep()
      long getElapsedExecutionTime()
      Gets the clock time in milliseconds since the iterative process was initialized
      long getEndExecutionTime()
      Returns system time in milliseconds that the iterative process ended
      int getEndingStateIndicator()
      Returns the ending state indicator
      java.lang.String getEndingStateIndicatorAsString()
      Returns a string representation of the ending state indicator COMPLETED_ALL_STEPS_MSG EXCEEDED_EXECUTION_TIME_MSG MET_STOPPING_CONDITION_MSG UNFINISHED_MSG
      long getId()
      Returns the id for this iterative process
      IPLogReport getLogReport()
      Returns a reference to the current log report.
      long getMaximumAllowedExecutionTime()
      Returns maximum (real) clock time allocated for the iterative process
      java.lang.String getName()
      Gets the name.
      long getNumberStepsCompleted()
      Returns the number of steps completed since the iterative process was last initialized
      boolean getSaveStepOption()
      Gets the save step option, true means that the steps will be saved by the iterative process into a Collection after running
      java.util.Iterator<T> getStepIterator()
      Returns an iterator to the saved steps
      java.util.List<T> getStepList()
      Returns an unmodifiable list view of the steps that have been saved
      boolean getStoppingFlag()
      Returns the stopping flag
      java.lang.String getStoppingMessage()
      A string message for why stop() was called.
      protected abstract boolean hasNext()
      This method should check to see if another step is necessary for the iterative process.
      void initialize()
      Initializes the iterative process prior to running any steps This must be done prior to calling runNext();
      protected void initializeIterations()  
      boolean isCreated()
      Checks if the iterative process is in the created state.
      boolean isDone()
      A flag to indicate whether the iterative process is done A iterative process can be done if: 1) it ran all of its steps 2) it was ended by a client prior to completing all of its steps 3) it ended because it exceeded its maximum allowable execution time before completing all of its steps.
      boolean isEnded()
      Checks if the iterative process is in the ended state After the iterative process has been ended this method will return true
      boolean isExecutionTimeExceeded()
      Returns if the elapsed execution time exceeds the maximum time allowed.
      boolean isInitialized()
      Checks if the iterative process is in the initialized state After the iterative process has been initialized this method will return true
      boolean isRunning()
      An iterative process is running if it is been told to run (i.e.
      boolean isRunningStep()
      Indicates that the iterative process is currently running an individual step
      boolean isStepCompleted()
      Checks if the iterative process is in the completed step state After the iterative process has successfully completed a step this method will return true
      boolean isUnfinished()
      The iterative process may end by a variety of means, this method checks if the iterative process ended but was unfinished, not all steps completed
      protected abstract T next()
      This method should return the next step to be executed in the iterative process or null if no more steps can be executed.
      boolean noStepsExecuted()
      Indicates that the iterative process ended because of no steps
      void run()
      Runs all of the steps of the iterative process.
      protected void runAll_()
      Runs all of the steps.
      void runNext()
      Runs the next step in the iterative process
      protected void runNext_()  
      protected abstract void runStep()
      This method tells the iterative process to execute the current step.
      protected void setId()
      Can be overridden to supply a unique id to the object By default a simple static counter is used to assign a number as instances are created
      void setMaximumExecutionTime​(long milliseconds)
      Set the maximum allotted (suggested) execution (real) clock for the entire iterative process.
      void setName​(java.lang.String str)
      Sets the name
      void setSaveStepOption​(boolean option)
      Sets the save step option, true means that the steps will be saved by the iterative process into a Collection after running
      protected void setState​(IterativeProcess.IterativeState state)
      The method is used to set the state and notify observers of the change
      void stop()
      This sets a flag to indicate to the process that is should stop after the next step is completed.
      void stop​(java.lang.String msg)
      This sets a flag to indicate to the process that is should stop after the next step is completed.
      boolean stoppedByCondition()
      The iterative process may end by a variety of means, this method checks if the iterative process ended because it was stopped
      java.lang.String toString()
      Gets a string for the iterative process.
      void turnOffLogReport()
      Turns off log reporting.
      void turnOnLogReport​(java.nio.file.Path pathToFile)
      Turns on the log report.
      void turnOnTimer​(long milliseconds)
      This method will cause the a timer to start allowing a TimerTask to be scheduled.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • NO_STEPS_EXECUTED

        public static final int NO_STEPS_EXECUTED
        Indicates whether the iterative process haD no steps to run
      • COMPLETED_ALL_STEPS

        public static final int COMPLETED_ALL_STEPS
        Indicates whether the iterative process has completed running all steps
      • EXCEEDED_EXECUTION_TIME

        public static final int EXCEEDED_EXECUTION_TIME
        Indicates whether the iterative process has exceeded its maximum execution time
      • MET_STOPPING_CONDITION

        public static final int MET_STOPPING_CONDITION
        Indicates whether the iterative process ended due to the being stopped
      • UNFINISHED

        public static final int UNFINISHED
        Indicates that the iterative process is in progress
      • NO_STEPS_EXECUTED_MSG

        protected java.lang.String NO_STEPS_EXECUTED_MSG
        Message used when process completes all steps
      • COMPLETED_ALL_STEPS_MSG

        protected java.lang.String COMPLETED_ALL_STEPS_MSG
        Message used when process completes all steps
      • EXCEEDED_EXECUTION_TIME_MSG

        protected java.lang.String EXCEEDED_EXECUTION_TIME_MSG
        Message used when process exceeds its execution time
      • MET_STOPPING_CONDITION_MSG

        protected java.lang.String MET_STOPPING_CONDITION_MSG
        Message used when process stops because it met a condition
      • UNFINISHED_MSG

        protected java.lang.String UNFINISHED_MSG
        Message used when process is not finished
      • myId

        protected long myId
        The id of this object
      • myName

        protected java.lang.String myName
        The name of this step
      • myBeginExecutionTime

        protected long myBeginExecutionTime
        The wall clock time in milliseconds that the iterative process started
      • myEndExecutionTime

        protected long myEndExecutionTime
        The wall clock time in milliseconds that the iterative process ended
      • myMaxAllowedExecutionTime

        protected long myMaxAllowedExecutionTime
        The maximum allowable execution time "wall" clock time for the iterative process to complete processing in milliseconds
      • myDoneFlag

        protected boolean myDoneFlag
        A flag to indicate whether the iterative process is done A iterative process can be done if: 1) it ran all of its steps 2) it was canceled by a client prior to completing all of its steps 3) it exceeded its maximum allowable execution time before completing all of its steps.
      • myRunningFlag

        protected boolean myRunningFlag
        Indicates that the iterative process is running
      • myRunningStepFlag

        protected boolean myRunningStepFlag
        Indicates if the iterative process is currently running an individual step, true if the step is in progress
      • myEndingStateIndicator

        protected int myEndingStateIndicator
        indicates how the iterative process ended
      • myCurrentStep

        protected T myCurrentStep
        A reference to an object related to the current step of the process It can be passed to observers
      • mySteps

        protected java.util.List<T> mySteps
        A collection of all the steps that have been run by this iterative process.
      • mySaveStepOption

        protected boolean mySaveStepOption
        A flag to indicate whether or not the iterative process will save the steps as they are created and then run in a Collection The default is FALSE (they will be not be saved).
      • myIPLogReport

        protected IPLogReport myIPLogReport
        Used to log state changes
      • myCreatedState

        protected final IterativeProcess.Created myCreatedState
        A reference to the created state for the iterative process A iterative process is in the created state when it is first constructed and can then only transition to the initialized state
      • myInitializedState

        protected final IterativeProcess.Initialized myInitializedState
        A reference to the initialized state of the iterative process A iterative process is in the initialized state after the initialize() method is called from a proper state.
      • myStepCompletedState

        protected final IterativeProcess.StepCompleted myStepCompletedState
        A reference to the step completed state of the iterative process A iterative process is in the step completed state after the runNext method is called from a proper state
      • myEndedState

        protected final IterativeProcess.Ended myEndedState
        A reference to the ended state of the iterative process A iterative process is in the ended state after the process is told to end
      • myTimer

        protected java.util.Timer myTimer
        A Timer used to perform timed task e.g. displaying information about the IterativeProcess
      • myTBConsoleUpdates

        protected long myTBConsoleUpdates
        The time between task invocations for the Timer and its TimerTask
      • myTimerTask

        protected java.util.TimerTask myTimerTask
        The task that the timer uses
      • myInitFlag

        protected boolean myInitFlag
        A flag that indicates whether or not the iterative process has already been initialized, false means it has not been initialized, true means that it has been initialized
      • myStepCounter

        protected long myStepCounter
        Counts the number of steps executed since the last time the process was initialized
      • myObservableComponent

        protected ObservableComponent myObservableComponent
        Allows the IterativeProcess to be observable. Observers are notified when the state changes Created, Initialized, StepCompleted, Ended Observers have access to the IterativeProcess and the current step T
    • Constructor Detail

      • IterativeProcess

        public IterativeProcess()
        Constructs an iterative process with default name
      • IterativeProcess

        public IterativeProcess​(java.lang.String name)
        Constructs an iterative process with the given name
        Parameters:
        name - the name of the process
    • Method Detail

      • getName

        public final java.lang.String getName()
        Gets the name.
        Specified by:
        getName in interface GetNameIfc
        Returns:
        The name of object.
      • setName

        public final void setName​(java.lang.String str)
        Sets the name
        Parameters:
        str - The name as a string.
      • getId

        public final long getId()
        Returns the id for this iterative process
        Returns:
        the id
      • setId

        protected final void setId()
        Can be overridden to supply a unique id to the object By default a simple static counter is used to assign a number as instances are created
      • toString

        public java.lang.String toString()
        Gets a string for the iterative process.
        Overrides:
        toString in class java.lang.Object
        Returns:
        Yields the name and other facts for the iterative process.
      • getCurrentStateAsString

        public final java.lang.String getCurrentStateAsString()
        Gets the current state as a string
        Returns:
        the current state as a string
      • getEndingStateIndicator

        public final int getEndingStateIndicator()
        Returns the ending state indicator
        Returns:
        an integer representing the ending state
      • getEndingStateIndicatorAsString

        public java.lang.String getEndingStateIndicatorAsString()
        Returns a string representation of the ending state indicator COMPLETED_ALL_STEPS_MSG EXCEEDED_EXECUTION_TIME_MSG MET_STOPPING_CONDITION_MSG UNFINISHED_MSG
        Returns:
        the string
      • isDone

        public final boolean isDone()
        A flag to indicate whether the iterative process is done A iterative process can be done if: 1) it ran all of its steps 2) it was ended by a client prior to completing all of its steps 3) it ended because it exceeded its maximum allowable execution time before completing all of its steps. 4) its end condition was satisfied
        Specified by:
        isDone in interface IterativeProcessIfc
        Returns:
        true if done
      • isCreated

        public final boolean isCreated()
        Description copied from interface: IterativeProcessIfc
        Checks if the iterative process is in the created state. If the iterative process is in the created state this method will return true
        Specified by:
        isCreated in interface IterativeProcessIfc
        Returns:
        true if in the created state
      • getBeginExecutionTime

        public final long getBeginExecutionTime()
        Returns system time in milliseconds that the iterative process started
        Specified by:
        getBeginExecutionTime in interface IterativeProcessIfc
        Returns:
        the number as a long
      • getElapsedExecutionTime

        public final long getElapsedExecutionTime()
        Description copied from interface: IterativeProcessIfc
        Gets the clock time in milliseconds since the iterative process was initialized
        Specified by:
        getElapsedExecutionTime in interface IterativeProcessIfc
        Returns:
        a long representing the elapsed time
      • getEndExecutionTime

        public final long getEndExecutionTime()
        Description copied from interface: IterativeProcessIfc
        Returns system time in milliseconds that the iterative process ended
        Specified by:
        getEndExecutionTime in interface IterativeProcessIfc
        Returns:
        the number as a long
      • getMaximumAllowedExecutionTime

        public final long getMaximumAllowedExecutionTime()
        Description copied from interface: IterativeProcessIfc
        Returns maximum (real) clock time allocated for the iterative process
        Specified by:
        getMaximumAllowedExecutionTime in interface IterativeProcessIfc
        Returns:
        the number as long representing milliseconds
      • setMaximumExecutionTime

        public final void setMaximumExecutionTime​(long milliseconds)
        Description copied from interface: IterativeProcessIfc
        Set the maximum allotted (suggested) execution (real) clock for the entire iterative process. This is a suggested time because the execution time requirement is only checked after the completion of an individual step After it is discovered that cumulative time for executing the step has exceeded the maximum time, then the iterative process will be ended (perhaps) not completing other steps.
        Specified by:
        setMaximumExecutionTime in interface IterativeProcessIfc
        Parameters:
        milliseconds - the time
      • getSaveStepOption

        public final boolean getSaveStepOption()
        Gets the save step option, true means that the steps will be saved by the iterative process into a Collection after running
        Returns:
        flag indicating the option
      • setSaveStepOption

        public final void setSaveStepOption​(boolean option)
        Sets the save step option, true means that the steps will be saved by the iterative process into a Collection after running
        Parameters:
        option - true if option is on
      • getStepIterator

        public final java.util.Iterator<T> getStepIterator()
        Returns an iterator to the saved steps
        Returns:
        an iterator
      • getStepList

        public final java.util.List<T> getStepList()
        Returns an unmodifiable list view of the steps that have been saved
        Returns:
        the list
      • getCurrentStep

        public final T getCurrentStep()
        Returns the current step for the iterative process the step that is or has just completed processing Note: Sub-classes are responsible for properly setting the current step when a step is run via runStep()
        Returns:
        the current step
      • getNumberStepsCompleted

        public final long getNumberStepsCompleted()
        Description copied from interface: IterativeProcessIfc
        Returns the number of steps completed since the iterative process was last initialized
        Specified by:
        getNumberStepsCompleted in interface IterativeProcessIfc
        Returns:
        the number of steps completed
      • turnOnLogReport

        public void turnOnLogReport​(java.nio.file.Path pathToFile)
        Description copied from interface: IterativeProcessIfc
        Turns on the log report. This report yields a text file of the state changes for the iterative process
        Specified by:
        turnOnLogReport in interface IterativeProcessIfc
        Parameters:
        pathToFile - specifies a prefix name for the report
      • turnOnTimer

        public final void turnOnTimer​(long milliseconds)
        Description copied from interface: IterativeProcessIfc
        This method will cause the a timer to start allowing a TimerTask to be scheduled. This method causes a print to console task to be run which prints the elapsed time since initializing the iterative process.
        Specified by:
        turnOnTimer in interface IterativeProcessIfc
        Parameters:
        milliseconds - the time for the timer
      • isInitialized

        public final boolean isInitialized()
        Description copied from interface: IterativeProcessIfc
        Checks if the iterative process is in the initialized state After the iterative process has been initialized this method will return true
        Specified by:
        isInitialized in interface IterativeProcessIfc
        Returns:
        true if initialized
      • isRunning

        public final boolean isRunning()
        Description copied from interface: IterativeProcessIfc
        An iterative process is running if it is been told to run (i.e. runNext()) but has not yet been told to end().
        Specified by:
        isRunning in interface IterativeProcessIfc
        Returns:
        true if running
      • isRunningStep

        public final boolean isRunningStep()
        Description copied from interface: IterativeProcessIfc
        Indicates that the iterative process is currently running an individual step
        Specified by:
        isRunningStep in interface IterativeProcessIfc
        Returns:
        true if the step is in progress
      • isStepCompleted

        public final boolean isStepCompleted()
        Description copied from interface: IterativeProcessIfc
        Checks if the iterative process is in the completed step state After the iterative process has successfully completed a step this method will return true
        Specified by:
        isStepCompleted in interface IterativeProcessIfc
        Returns:
        true if the iterative process completed the step
      • isEnded

        public final boolean isEnded()
        Description copied from interface: IterativeProcessIfc
        Checks if the iterative process is in the ended state After the iterative process has been ended this method will return true
        Specified by:
        isEnded in interface IterativeProcessIfc
        Returns:
        true if ended
      • noStepsExecuted

        public final boolean noStepsExecuted()
        Description copied from interface: IterativeProcessIfc
        Indicates that the iterative process ended because of no steps
        Specified by:
        noStepsExecuted in interface IterativeProcessIfc
        Returns:
        True if no steps are executed
      • allStepsCompleted

        public final boolean allStepsCompleted()
        Description copied from interface: IterativeProcessIfc
        The iterative process may end by a variety of means, this method checks if the iterative process ended because it ran all of its steps
        Specified by:
        allStepsCompleted in interface IterativeProcessIfc
        Returns:
        true if all completed
      • executionTimeExceeded

        public final boolean executionTimeExceeded()
        Description copied from interface: IterativeProcessIfc
        The iterative process may end by a variety of means, this method checks if the iterative process ended because it timed out
        Specified by:
        executionTimeExceeded in interface IterativeProcessIfc
        Returns:
        true if exceeded
      • stoppedByCondition

        public final boolean stoppedByCondition()
        Description copied from interface: IterativeProcessIfc
        The iterative process may end by a variety of means, this method checks if the iterative process ended because it was stopped
        Specified by:
        stoppedByCondition in interface IterativeProcessIfc
        Returns:
        true if it was stopped via stop()
      • isUnfinished

        public final boolean isUnfinished()
        Description copied from interface: IterativeProcessIfc
        The iterative process may end by a variety of means, this method checks if the iterative process ended but was unfinished, not all steps completed
        Specified by:
        isUnfinished in interface IterativeProcessIfc
        Returns:
        true if the process is not finished
      • initialize

        public final void initialize()
        Description copied from interface: IterativeProcessIfc
        Initializes the iterative process prior to running any steps This must be done prior to calling runNext();
        Specified by:
        initialize in interface IterativeProcessIfc
      • run

        public final void run()
        Description copied from interface: IterativeProcessIfc
        Runs all of the steps of the iterative process. If the iterative process has not been initialized, then it will automatically be initialized. After attempting to run the steps, the process will be in the end() state. The process may or may not complete all of its steps.
        Specified by:
        run in interface IterativeProcessIfc
      • stop

        public final void stop​(java.lang.String msg)
        Description copied from interface: IterativeProcessIfc
        This sets a flag to indicate to the process that is should stop after the next step is completed. This is different than end(). Calling end() immediately places the process in the End state. The process needs to be in a valid state before end() can be used. Calling stop tells the process to eventually get into the end state. stop() can be used to arbitrarily stop the process based on some user defined condition.
        Specified by:
        stop in interface IterativeProcessIfc
        Parameters:
        msg - A string to represent the reason for the stopping
      • stop

        public final void stop()
        Description copied from interface: IterativeProcessIfc
        This sets a flag to indicate to the process that is should stop after the next step is completed. This is different than end(). Calling end() immediately places the process in the End state. The process needs to be in a valid state before end() can be used. Calling stop tells the process to eventually get into the end state. stop() can be used to arbitrarily stop the process based on some user defined condition.
        Specified by:
        stop in interface IterativeProcessIfc
      • getStoppingFlag

        public final boolean getStoppingFlag()
        Description copied from interface: IterativeProcessIfc
        Returns the stopping flag
        Specified by:
        getStoppingFlag in interface IterativeProcessIfc
        Returns:
        true if the process has been told to stop via stop()
      • end

        public final void end​(java.lang.String msg)
        The iterative process will continue until there are no more steps or its maximum execution time has been reached, whichever comes first. If this method is called the iterative process will end processing (terminate) before the next step and not process the next step in the process. The current step will be completed. This method can be used to end the process at an arbitrary step. Once ended, the process must be initialized to run again.
        Specified by:
        end in interface IterativeProcessIfc
        Parameters:
        msg - an option message to indicate the reason for stopping
      • end

        public final void end()
        The iterative process will continue until there are no more steps or its maximum execution time has been reached, whichever comes first. If this method is called the iterative process will end processing (terminate) before the next step and not process the next step in the process. The current step will be completed. This method can be used to end the process at an arbitrary step. Once ended, the process must be restarted via initialize().
        Specified by:
        end in interface IterativeProcessIfc
      • hasNext

        protected abstract boolean hasNext()
        This method should check to see if another step is necessary for the iterative process. True means that the process has another step to be executed. False, means that no more steps are available for execution.
        Returns:
        true if another step is present
      • next

        protected abstract T next()
        This method should return the next step to be executed in the iterative process or null if no more steps can be executed. It should advance the current step to the next step if it is available
        Returns:
        the type of the step
      • runStep

        protected abstract void runStep()
        This method tells the iterative process to execute the current step. Typical usage is to call this after calling next() to advance to the next step. This method should throw a NoSuchStepException if there are no more steps to run and it is told to run the step.
      • consoleOutput

        protected void consoleOutput()
        Can be overwritten by subclasses to have output when the console flag is on
      • contains

        public boolean contains​(ObserverIfc observer)
        Description copied from interface: ObservableIfc
        Returns true if the observer is already attached
        Specified by:
        contains in interface ObservableIfc
        Parameters:
        observer - the observer to check
        Returns:
        true if attached
      • deleteObservers

        public final void deleteObservers()
        Description copied from interface: ObservableIfc
        Deletes all the observers from the observable
        Specified by:
        deleteObservers in interface ObservableIfc
      • deleteObserver

        public final void deleteObserver​(ObserverIfc observer)
        Description copied from interface: ObservableIfc
        Allows the deletion (removing) of an observer from the observable
        Specified by:
        deleteObserver in interface ObservableIfc
        Parameters:
        observer - the observer to delete
      • countObservers

        public final int countObservers()
        Description copied from interface: ObservableIfc
        Returns how many observers are currently observing the observable
        Specified by:
        countObservers in interface ObservableIfc
        Returns:
        number of observers
      • addObserver

        public final void addObserver​(ObserverIfc observer)
        Description copied from interface: ObservableIfc
        Allows the adding (attaching) of an observer to the observable
        Specified by:
        addObserver in interface ObservableIfc
        Parameters:
        observer - the observer to attach
      • isExecutionTimeExceeded

        public final boolean isExecutionTimeExceeded()
        Returns if the elapsed execution time exceeds the maximum time allowed. Only true if the maximum was set and elapsed time is greater than or equal to getMaximumAllowedExecutionTime()
        Specified by:
        isExecutionTimeExceeded in interface IterativeProcessIfc
        Returns:
        true if the execution time exceeds getMaximumAllowedExecutionTime()
      • setState

        protected final void setState​(IterativeProcess.IterativeState state)
        The method is used to set the state and notify observers of the change
        Parameters:
        state - the state
      • initializeIterations

        protected void initializeIterations()
      • runAll_

        protected final void runAll_()
        Runs all of the steps. Each step is run, and finally the iterative process is ended.
      • runNext_

        protected void runNext_()
      • checkStoppingCondition

        protected void checkStoppingCondition()
      • checkStoppingCondition_

        protected void checkStoppingCondition_()
      • endIterations

        protected void endIterations()