• class ConsoleDialogueManager
    extends java.lang.Object

    The Console Dialogue Manager Class

    As class: manages resources needed to maintain a console dialogue and executes transitions between console dialogue levels.
    As instance: manages and executes the lifecycle of one level in a console dialogue.

    First of the two parts that make up my ConsoleDialogueAPI, a lightweight programming interface for creating console dialogues.

    Abbreviations you might encounter in this documentation:
    CDM = ConsoleDialogueManager
    CDE = ConsoleDialogueElement

    Since:
    2018-02-14
    Version:
    1.0
    Author:
    Daniel Giljam
    • Field Summary


      Fields 
      Modifier and Type Field Description
      private static List<CDE> activeCDEs
      List that hold all the active CDEs + the order they "check" in.
      private static java.lang.String activeHelpMessage
      The message shown by the default help CDE.
      private static java.lang.String activeInitialMessage
      The currently active initial message.
      private List<CDE> cdElements
      This instance's CDEs + a variable for potentially backing up previously active CDEs.
      private List<CDE> cdElementsBackup
      This instance's CDEs + a variable for potentially backing up previously active CDEs.
      private static CDE help
      The default help CDE.
      private static java.lang.String HELP_PATTERN
      The regex string defining the pattern used for matching by the default help CDE.
      private java.lang.String helpMessage
      This instance's help message + a variable for potentially backing up a previously active help message.
      private java.lang.String helpMessageBackup
      This instance's help message + a variable for potentially backing up a previously active help message.
      private java.lang.String initalMessage
      Holds instance-specific "initial message" - a message shown at the creation of an CDM + a variable for potentially backing up a previously active inital message.
      private java.lang.String initialMessageBackup
      Holds instance-specific "initial message" - a message shown at the creation of an CDM + a variable for potentially backing up a previously active inital message.
      private static java.lang.String input
      String that holds what is in this documentation referred to as the user input.
      private static java.util.Scanner scanner
      Scanner -object for fetching what the user types in the terminal.
      private static java.lang.String UNABLE_TO_INTERPRET_MESSAGE
      The default message shown when user input didn't match any of the patterns defined in the CDEs.
    • Constructor Summary

      Constructors 
      Constructor Description
      < class="memberNameLink">ConsoleDialogueManager​(java.util.List<ConsoleDialogueElement> cdElements, java.lang.String initialMessage, java.lang.String helpMessage, boolean queue, boolean merge)
      CDM Constructor
    • Method Summary

      All Methods
      Modifier and Type Method Description
      private void CollapseCD​()
      CollapseCD
      private void ConsoleDialogue​()
      ConsoleDialogue
      private void InitializeCD​(boolean queue, boolean merge)
      InitializeCD
      • Methods inherited from class java.lang.Object

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

      • activeCDEs

        private static java.util.List<ConsoleDialogueElement> activeCDEs
        List that hold all the active CDEs + the order they "check" in.
      • activeHelpMessage

        private static java.lang.String activeHelpMessage
        The message shown by the default help CDE.
      • activeInitialMessage

        private static java.lang.String activeInitialMessage
        The currently active initial message.
      • cdElements

        private java.util.List<ConsoleDialogueElement> cdElements
        This instance's CDEs + a variable for potentially backing up previously active CDEs.
      • cdElementsBackup

        private java.util.List<ConsoleDialogueElement> cdElementsBackup
        This instance's CDEs + a variable for potentially backing up previously active CDEs.
      • help

        private static final ConsoleDialogueElement help
        The default help CDE.
      • HELP_PATTERN

        private static final java.lang.String HELP_PATTERN
        The regex string defining the pattern used for matching by the default help CDE.
        See Also:
        Constant Field Values
      • helpMessage

        private java.lang.String helpMessage
        This instance's help message + a variable for potentially backing up a previously active help message.
      • helpMessageBackup

        private java.lang.String helpMessageBackup
        This instance's help message + a variable for potentially backing up a previously active help message.
      • initalMessage

        private java.lang.String initalMessage
        Holds instance-specific "initial message" - a message shown at the creation of an CDM + a variable for potentially backing up a previously active inital message.
      • initialMessageBackup

        private java.lang.String initialMessageBackup
        Holds instance-specific "initial message" - a message shown at the creation of an CDM + a variable for potentially backing up a previously active inital message.
      • input

        private static java.lang.String input
        String that holds what is in this documentation referred to as the user input.
      • scanner

        private static final java.util.Scanner scanner
        Scanner -object for fetching what the user types in the terminal. (The delimiter is set to "\n" so that the Scanner.next() -function delivers everything the user types on the terminal line as one whole string, whitespaces included.)
      • UNABLE_TO_INTERPRET_MESSAGE

        private static final java.lang.String UNABLE_TO_INTERPRET_MESSAGE
        The default message shown when user input didn't match any of the patterns defined in the CDEs.
        See Also:
        Constant Field Values
    • Constructor Detail

      • ConsoleDialogueManager

        ConsoleDialogueManager​(java.util.List<ConsoleDialogueElement> cdElements,
                               java.lang.String initialMessage,
                               java.lang.String helpMessage,
                               boolean queue,
                               boolean merge)

        CDM Constructor

        Saves parameters in their corresponding instance-specific variables, then sets off the InitializeCD() -method.
        Parameters:
        cdElements - a List containing the CDEs
        initialMessage - a string that will be the CDM's initial message
        helpMessage - a string that will be set as the CDM's help message
        queue - boolean that, if set to true, tells the CDM to just queue up the CDEs and then move on with the code, rather than start the dialogue immediately
        merge - boolean that if set to true, tells the CDM to not replace the "queue", but rather add on top of what was already there
    • Method Detail

      • CollapseCD

        private void CollapseCD​()

        CollapseCD

        Restores the backed up values of static variables.
      • ConsoleDialogue

        private void ConsoleDialogue​()

        ConsoleDialogue

        The essence of this class. Explained in greater detail in comments within the code.
      • InitializeCD

        private void InitializeCD​(boolean queue,
                                  boolean merge)

        InitializeCD

        Method that:
        1. Backs up static variables (if previously initialized)
        2. Assigns the content of the instance-specific variables to the corresponding static "active" variables (if the merge boolean in the constructor was true, then - as the boolean says - the content of the instance-specific variables will be merged with any content pre-occupying the static "active" variables, else - if merge is false - any pre-occupying content will be overwritten in the static "active" variables)
        3. Displays the initial message (if there is one)
        4. Starts the ConsoleDialogue() -method (if the queue boolean in the constructor was true, then the ConsoleDialogue() -method won't start, which means this CDM has run it's course)
        Parameters:
        queue - boolean that, if set to true, tells the CDM to just queue up the CDEs and then move on with the code, rather than start the dialogue immediately (forwarded from constructor)
        merge - boolean that if set to true, tells the CDM to not replace the "queue", but rather add on top of what was already there (forwarded from constructor)