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.)

public class NumberInput<U extends Number> extends Input<U,NumberInput<U>>
A generic class for handling numeric user input with validation.
  • Constructor Details

    • NumberInput

      public NumberInput(Class<U> type)
      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

      public U read() throws InputValidationException
      Description copied from class: Input
      Read the input value
      Specified by:
      read in class Input<U extends Number,NumberInput<U extends Number>>
      Returns:
      the input value
      Throws:
      InputValidationException - if the input is invalid and retryOnInvalid is false
    • setAllowComma

      public NumberInput<U> setAllowComma(boolean allowComma)
      Set whether to allow commas as decimal separators.
      Parameters:
      allowComma - Whether to allow commas as decimal separators.
      Returns:
      The current NumberInput object.
    • setInline

      public NumberInput<U> setInline(boolean inline)
      Set whether to display the input prompt inline.
      Parameters:
      inline - Whether to display the input prompt inline.
      Returns:
      The current NumberInput object.