• class ConsoleDialogueElement
    extends java.lang.Object

    The Console Dialogue Element Class

    Responsible for the detecting and executing of one console dialogue command or the interpreting and parsing of one kind of expected user input

    The second 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 java.lang.Runnable action
      A slot for the code that should be executed after a positive check.
      (package private) boolean lastWord
      A slot for the value returned by the check() -function to the "last word" boolean in the process communication variable in the ConsoleDialogue() -method.
      (package private) java.util.regex.Matcher matcher
      Used to see if the Pattern object's pattern matches with a given string (user input, of course, in this case).
      private java.util.regex.Pattern pattern
      The Pattern object – initiated by the constructor with the regex string provided as parameter.
    • Constructor Summary

      Constructors 
      Constructor Description
      ConsoleDialogueElement​(java.lang.Runnable action, java.lang.String pattern, boolean terminal)
      CDE Constructor
    • Method Summary

      All Methods
      Modifier and Type Method Description
      (package private) boolean[] check​(java.lang.String input)
      check
      • Methods inherited from class java.lang.Object

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

      • action

        private java.lang.Runnable action
        A slot for the code that should be executed after a positive check.
      • lastWord

        boolean lastWord
        A slot for the value returned by the check() -function to the "last word" boolean in the process communication variable in the ConsoleDialogue() -method.
      • matcher

        java.util.regex.Matcher matcher
        Used to see if the Pattern object's pattern matches with a given string (user input, of course, in this case).
      • pattern

        private java.util.regex.Pattern pattern
        The Pattern object – initiated by the constructor with the regex string provided as parameter.
    • Constructor Detail

      • ConsoleDialogueElement

        ConsoleDialogueElement​(java.lang.Runnable action,
                               java.lang.String pattern,
                               boolean terminal)

        CDE Constructor

        Saves parameters in their corresponding instance-specific variables.
        Parameters:
        action - a runnable with the code that should be executed after a positive check
        pattern - a regex string defining the pattern used for matching by this CDE
        terminal - if true, means that "the element is terminal" – a "positive check" with this CDE doesn't only stop "the interpreter", but also ends the "prompter" (see comments within the ConsoleDialogue() -method's code for explanations on what the words surrounded by double quotation marks mean)
    • Method Detail

      • check

        boolean[] check​(java.lang.String input)

        check

        Explained in greater detail in comments within the code.
        Parameters:
        input - the latest user input string
        Returns:
        array containing two booleans that in the ConsoleDialogue() -method become the new values of the "process communication" variables