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 Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractPromptResult(T prompt) Create a new AbstractPromptResult with the given prompt. -
Method Summary
Modifier and TypeMethodDescriptionvoidapplyFilter(String filteredResult) Apply a filter to this result.Get the prompt that generated this result.protected abstract StringGet the raw (unfiltered) result value.final StringReturns 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, waitMethods inherited from interface org.jline.prompt.PromptResult
getDisplayResult
-
Constructor Details
-
AbstractPromptResult
Create a new AbstractPromptResult with the given prompt.- Parameters:
prompt- the associated Prompt, or null if none
-
-
Method Details
-
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:
-
applyFilter
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
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
Get the raw (unfiltered) result value. Subclasses must implement this instead ofgetResult().- Returns:
- the raw result value
-