Class ValidatingPrompt

    • Constructor Detail

      • ValidatingPrompt

        public ValidatingPrompt()
    • Method Detail

      • acceptInput

        public Prompt acceptInput​(ConversationContext context,
                                  String input)
        Accepts and processes input from the user and validates it. If validation fails, this prompt is returned for re-execution, otherwise the next Prompt in the prompt graph is returned.
        Specified by:
        acceptInput in interface Prompt
        Parameters:
        context - Context information about the conversation.
        input - The input text from the user.
        Returns:
        This prompt or the next Prompt in the prompt graph.
      • blocksForInput

        public boolean blocksForInput​(ConversationContext context)
        Ensures that the prompt waits for the user to provide input.
        Specified by:
        blocksForInput in interface Prompt
        Parameters:
        context - Context information about the conversation.
        Returns:
        True.
      • isInputValid

        protected abstract boolean isInputValid​(ConversationContext context,
                                                String input)
        Override this method to check the validity of the player's input.
        Parameters:
        context - Context information about the conversation.
        input - The player's raw console input.
        Returns:
        True or false depending on the validity of the input.
      • acceptValidatedInput

        protected abstract Prompt acceptValidatedInput​(ConversationContext context,
                                                       String input)
        Override this method to accept and processes the validated input from the user. Using the input, the next Prompt in the prompt graph should be returned.
        Parameters:
        context - Context information about the conversation.
        input - The validated input text from the user.
        Returns:
        The next Prompt in the prompt graph.
      • getFailedValidationText

        protected String getFailedValidationText​(ConversationContext context,
                                                 String invalidInput)
        Optionally override this method to display an additional message if the user enters an invalid input.
        Parameters:
        context - Context information about the conversation.
        invalidInput - The invalid input provided by the user.
        Returns:
        A message explaining how to correct the input.