Package org.strassburger.tui4j.input
Class NumberInput<U extends Number>
java.lang.Object
org.strassburger.tui4j.input.Input<U,NumberInput<U>>
org.strassburger.tui4j.input.NumberInput<U>
- Type Parameters:
U- the type of number (Integer, Double, etc.)
A generic class for handling numeric user input with validation.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionread()Read the input valuesetAllowComma(boolean allowComma) Set whether to allow commas as decimal separators.setInline(boolean inline) Set whether to display the input prompt inline.Methods inherited from class org.strassburger.tui4j.input.Input
addValidationRule, addValidationRules, getCursor, getErrorMessage, getLabel, getPrinter, getScanner, isRetryOnInvalid, setCursor, setErrorMessage, setErrorMessage, setLabel, setLabel, setPrinter, setRetryOnInvalid, setScanner, validate
-
Constructor Details
-
NumberInput
Create a new NumberInput object.- Parameters:
type- The type of number to read (Integer, Double, etc.)Example usage:
NumberInput<Integer> input = new NumberInput<>(Integer.class) .setLabel("Enter an integer:") .setRetryOnInvalid(true); int value = input.read(); System.out.println("You entered: " + value);
-
-
Method Details
-
read
Description copied from class:InputRead the input value- Specified by:
readin classInput<U extends Number,NumberInput<U extends Number>> - Returns:
- the input value
- Throws:
InputValidationException- if the input is invalid and retryOnInvalid is false
-
setAllowComma
Set whether to allow commas as decimal separators.- Parameters:
allowComma- Whether to allow commas as decimal separators.- Returns:
- The current NumberInput object.
-
setInline
Set whether to display the input prompt inline.- Parameters:
inline- Whether to display the input prompt inline.- Returns:
- The current NumberInput object.
-