Class AbstractPromptResult<T extends Prompt>

java.lang.Object
org.jline.prompt.impl.AbstractPromptResult<T>
All Implemented Interfaces:
PromptResult<T>
Direct Known Subclasses:
DefaultCheckboxResult, DefaultChoiceResult, DefaultConfirmResult, DefaultEditorResult, DefaultInputResult, DefaultKeyPressResult, DefaultListResult, DefaultNoResult, DefaultSearchResult, DefaultToggleResult

public abstract class AbstractPromptResult<T extends Prompt> extends Object implements PromptResult<T>
Abstract base class for prompt results.
  • Constructor Details

    • AbstractPromptResult

      protected AbstractPromptResult(T prompt)
      Create a new AbstractPromptResult with the given prompt.
      Parameters:
      prompt - the associated Prompt, or null if none
  • Method Details

    • getPrompt

      public T getPrompt()
      Description copied from interface: PromptResult
      Get the prompt that generated this result.

      This method provides access to the original prompt configuration, allowing inspection of the prompt's properties such as available items, validation rules, or other configuration details.

      Example Usage:

      
       ListResult result = (ListResult) results.get("choice");
       ListPrompt prompt = result.getPrompt();
      
       if (prompt != null) {
           // Access prompt configuration
           String promptMessage = prompt.getMessage();
           List<ListItem> availableItems = prompt.getItems();
      
           // Validate selection against available options
           String selectedId = result.getSelectedId();
           boolean isValidSelection = availableItems.stream()
               .anyMatch(item -> item.getName().equals(selectedId));
       }
       
      Specified by:
      getPrompt in interface PromptResult<T extends Prompt>
      Returns:
      the prompt that generated this result, or null if not available
      See Also:
    • applyFilter

      public void applyFilter(String filteredResult)
      Apply a filter to this result. If set, getResult() will return the filtered value instead of the original.
      Parameters:
      filteredResult - the filtered result value
    • getResult

      public final String getResult()
      Returns the filtered result if a filter was applied, otherwise delegates to the subclass implementation via getRawResult().
      Specified by:
      getResult in interface PromptResult<T extends Prompt>
      Returns:
      the result as a string, never null
    • getRawResult

      protected abstract String getRawResult()
      Get the raw (unfiltered) result value. Subclasses must implement this instead of getResult().
      Returns:
      the raw result value