-
- Type Parameters:
T- the specific type of prompt that generated this result
- All Known Subinterfaces:
CheckboxResult,ChoiceResult,ConfirmResult,EditorResult,InputResult,KeyPressResult,ListResult,NoResult,SearchResult<T>,ToggleResult
- All Known Implementing Classes:
AbstractPromptResult,DefaultCheckboxResult,DefaultChoiceResult,DefaultConfirmResult,DefaultEditorResult,DefaultInputResult,DefaultKeyPressResult,DefaultListResult,DefaultNoResult,DefaultSearchResult,DefaultToggleResult
public interface PromptResult<T extends Prompt>Parameterized interface representing the result of a user prompt interaction.PromptResultprovides a type-safe way to access the results of user interactions with various prompt types. Each result is associated with the specific prompt that generated it, enabling access to both the user's response and the original prompt configuration.Type Safety
The interface is parameterized with the specific prompt type, ensuring compile-time type safety when accessing prompt-specific information:
ListResultextendsPromptResult<ListPrompt>CheckboxResultextendsPromptResult<CheckboxPrompt>ChoiceResultextendsPromptResult<ChoicePrompt>InputResultextendsPromptResult<InputPrompt>ConfirmResultextendsPromptResult<ConfirmPrompt>
Usage Examples
// Basic result access Map<String, ? extends PromptResult<? extends Prompt>> results = prompter.prompt(...); // Type-safe casting and access ListResult listResult = (ListResult) results.get("choice"); String selectedId = listResult.getSelectedId(); // Access the original prompt ListPrompt originalPrompt = listResult.getPrompt(); if (originalPrompt != null) { List<ListItem> availableItems = originalPrompt.getItems(); } // Generic result access String displayValue = listResult.getDisplayResult();Immutability
All prompt results are immutable value objects. Once created, their state cannot be modified. This ensures thread safety and prevents accidental modification of user responses.
- Since:
- 3.30.0
- See Also:
Prompt,Prompter.prompt(List, List)
-
-
Method Summary
All Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default java.lang.StringgetDisplayResult()Get a human-readable display representation of the result.default TgetPrompt()Get the prompt that generated this result.java.lang.StringgetResult()Get the raw result value as a string representation.
-
-
-
Method Detail
-
getResult
java.lang.String getResult()
Get the raw result value as a string representation.This method returns the user's response in its most basic string form. For selection-based prompts (list, checkbox, choice), this typically returns the ID(s) of selected items. For input prompts, this returns the entered text.
Examples:
- List prompt:
"option1" - Checkbox prompt:
"[option1, option3]" - Input prompt:
"user entered text" - Confirm prompt:
"YES"or"NO"
- Returns:
- the result as a string, never
null
- List prompt:
-
getDisplayResult
default java.lang.String getDisplayResult()
Get a human-readable display representation of the result.This method returns a formatted version of the result that is suitable for display to users. It may differ from
getResult()by providing more descriptive text or better formatting.The default implementation returns the same value as
getResult(). Specific result types may override this to provide more user-friendly formatting.- Returns:
- a display-friendly representation of the result, never
null
-
getPrompt
default T getPrompt()
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)); }- Returns:
- the prompt that generated this result, or
nullif not available - See Also:
Prompt
-
-