- 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 java.lang.Object implements PromptResult<T>
Abstract base class for prompt results.
-
-
Constructor Summary
Constructors Modifier Constructor Description protectedAbstractPromptResult(T prompt)Create a new AbstractPromptResult with the given prompt.
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description voidapplyFilter(java.lang.String filteredResult)Apply a filter to this result.TgetPrompt()Get the prompt that generated this result.protected abstract java.lang.StringgetRawResult()Get the raw (unfiltered) result value.java.lang.StringgetResult()Returns the filtered result if a filter was applied, otherwise delegates to the subclass implementation viagetRawResult().-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface org.jline.prompt.PromptResult
getDisplayResult
-
-
-
-
Constructor Detail
-
AbstractPromptResult
protected AbstractPromptResult(T prompt)
Create a new AbstractPromptResult with the given prompt.- Parameters:
prompt- the associated Prompt, or null if none
-
-
Method Detail
-
getPrompt
public T getPrompt()
Description copied from interface:PromptResultGet 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:
getPromptin interfacePromptResult<T extends Prompt>- Returns:
- the prompt that generated this result, or
nullif not available - See Also:
Prompt
-
applyFilter
public void applyFilter(java.lang.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 java.lang.String getResult()
Returns the filtered result if a filter was applied, otherwise delegates to the subclass implementation viagetRawResult().- Specified by:
getResultin interfacePromptResult<T extends Prompt>- Returns:
- the result as a string, never
null
-
getRawResult
protected abstract java.lang.String getRawResult()
Get the raw (unfiltered) result value. Subclasses must implement this instead ofgetResult().- Returns:
- the raw result value
-
-