java.lang.Object
nl.pim16aap2.animatedarchitecture.core.tooluser.Procedure

@ThreadSafe public final class Procedure extends Object
Represents a procedure as defined by a series of Steps.
  • Constructor Details

  • Method Details

    • getAllSteps

      public List<Step> getAllSteps()
      Getter for the steps in this procedure.
      Returns:
      A list containing all steps in this procedure including any that may have been completed already.
    • getStepByName

      public Optional<Step> getStepByName(String name)
      Retrieves a step by its Step.getName().
      Parameters:
      name - The name of the step to retrieve.
      Returns:
      The step, if it exists in this procedure.
    • insertStep

      public void insertStep(Step step)
      Inserts a step before the current step and goes to the previous step.

      After this call, getCurrentStep() will return the inserted step and goToNextStep() will proceed to the previous 'current' step.

      Parameters:
      step - The step to insert.
    • insertStep

      public void insertStep(String name)
      Inserts an existing, named step at the current position.

      See getStepByName(String) and insertStep(Step).

      Parameters:
      name - The name of the step to insert.
      Throws:
      NoSuchElementException - If no step can be found by that name.
    • hasNextStep

      public boolean hasNextStep()
      Checks if another step exists after the current one.
      Returns:
      True if the current step is followed by another one. When false, the current step is the final step.
    • goToNextStep

      public void goToNextStep()
      Advances to the next step.
    • skipToStep

      public boolean skipToStep(Step goalStep)
      Skips to a specific Step in this Procedure.

      If the step could not be found, the procedure will skip to the last step.

      Parameters:
      goalStep - The Step to jump to.
      Returns:
      True if the jump was successful, otherwise false.
    • applyStepExecutor

      public CompletableFuture<Boolean> applyStepExecutor(@Nullable @Nullable Object obj) throws IllegalArgumentException
      Applies some kind of input to the StepExecutor for the current step.
      Parameters:
      obj - The input to apply.
      Returns:
      True if the application was successful.
      Throws:
      IllegalArgumentException - If the input object is not of the expected type.
    • getCurrentStepMessage

      public Text getCurrentStepMessage()
      Gets the message for the current step, with all the variables filled in.
      Returns:
      The message for the current step.
    • getMessage

      public Text getMessage(@Nullable @Nullable Step step)
      Gets the message for a specific step, with all the variables filled in.

      If the step is null, a generic error message will be returned.

      A shortcut for getting the message for the current step is getCurrentStepMessage().

      Parameters:
      step - The step to get the message for.
      Returns:
      The message for the step.
    • getCurrentStepName

      public String getCurrentStepName()
      Gets the name of the current step.

      This is a shortcut for getStepName(Step) with the current step.

      Returns:
      The name of the current step.
    • getStepName

      public String getStepName(@Nullable @Nullable Step step)
      Gets the name of a specific step.

      If the step is null, a generic error message will be returned.

      A shortcut for getting the name of the current step is getCurrentStepName().

      Parameters:
      step - The step to get the name of.
      Returns:
      The name of the step.
    • waitForUserInput

      public boolean waitForUserInput()
      Whether the current step requires waiting for user input.
      Returns:
      True if the current step should wait for user input.
    • handleStepCompletion

      public void handleStepCompletion()
      Handles the completion of the current step.

      This will automatically move to the next step if implicitNextStep() returns true.

      If the current step is null, this will do nothing.

      This is a shortcut for implicitNextStep() and goToNextStep() (if the former returns true).

    • implicitNextStep

      public boolean implicitNextStep()
      Whether the current step should continue to the next step if execution was successful.

      If no next step (see hasNextStep()) is available, this will always return false.

      If this is false, the procedure should not be moved to the next step automatically, as this is supposed to be handled explicitly by the step executor itself.

      Returns:
      True if the current step should continue to the next step if execution was successful.
    • runCurrentStepPreparation

      @Nullable public @Nullable Step runCurrentStepPreparation()
      Runs the step preparation for the current step if applicable. See Step.getStepPreparation().
      Returns:
      The current step if it exists, otherwise null.
    • getCurrentStep

      @Nullable public @Nullable Step getCurrentStep()
    • getStepsCompleted

      public int getStepsCompleted()
      Gets the number of steps that have been completed.
      Returns:
      The number of steps that have been completed.
    • toString

      public String toString()
      Overrides:
      toString in class Object