Class InputValidator
java.lang.Object
theLocalLoop.InputValidator
This class is responsible for validating user input throughout the application.
It provides methods to ensure that inputs are of the correct type and format, such as integers, doubles, non-empty strings, specific options, valid passwords, and valid types. By centralizing input validation in this class, we can maintain cleaner code and ensure consistent validation across different parts of the application.
It provides methods to ensure that inputs are of the correct type and format, such as integers, doubles, non-empty strings, specific options, valid passwords, and valid types. By centralizing input validation in this class, we can maintain cleaner code and ensure consistent validation across different parts of the application.
-
Method Summary
Modifier and TypeMethodDescriptionstatic StringgetRequiredString(Scanner input, String prompt) Prompts the user for a non-empty string input.static LocalDategetValidDate(Scanner input, String prompt) Prompts the user to enter a date and validates that it is in the correct format (MM-dd-yyyy) and that it is not a past date.static doublegetValidDouble(Scanner input, String prompt) Prompts the user for a double input and validates that it is a positive number.static Constants.ValidFormatgetValidFormat(Scanner input, String prompt) Prompts the user to select an option from a predefined list of valid options.static intgetValidInt(Scanner input, String prompt, int min, int max) Prompts the user for an integer input and validates that it falls within a specified range.static StringgetValidPassword(Scanner input, String prompt) Prompts the user for a password input and validates that it meets specific criteria, such as minimum length, presence of uppercase letters, numbers, and symbols.static LocalTimegetValidTime(Scanner input, String prompt) Prompts the user to enter a time and validates that it is in the correct format (HH:mm).static ArrayList<Constants.ValidType> getValidTypes(Scanner input, String prompt) Prompts the user to enter a list of types and validates that each type is included in part of the ValidType enum class.
-
Method Details
-
getValidInt
Prompts the user for an integer input and validates that it falls within a specified range.
Checks for integer in PrintMenu, PrintDisplayMenu, PrintFilterMenu, and PrintSortMenu- Parameters:
input- The Scanner object used to read user input.prompt- The message displayed to the user when asking for input.min- The minimum acceptable integer value (inclusive).max- The maximum acceptable integer value (inclusive).- Returns:
- The valid integer input provided by the user.
-
getValidDouble
Prompts the user for a double input and validates that it is a positive number.
Checks for double in addEvent in EventManager- Parameters:
input- The Scanner object used to read user input.prompt- The message displayed to the user when asking for input.- Returns:
- The valid double input provided by the user.
-
getRequiredString
Prompts the user for a non-empty string input.
Checks for non-empty string in addEvent in EventManager for name, organizer, and location- Parameters:
input- The Scanner object used to read user input.prompt- The message displayed to the user when asking for input.- Returns:
- The valid non-empty string input provided by the user.
-
getValidFormat
Prompts the user to select an option from a predefined list of valid options.
Checks for specific options in addEvent in EventManager for type of event- Parameters:
input- The Scanner object used to read user input.prompt- The message displayed to the user when asking for input.- Returns:
- The valid option selected by the user, returned in the same case as defined in the options array.
-
getValidPassword
Prompts the user for a password input and validates that it meets specific criteria, such as minimum length, presence of uppercase letters, numbers, and symbols.
Checks for password in addEvent in EventManager- Parameters:
input- The Scanner object used to read user input.prompt- The message displayed to the user when asking for input.- Returns:
- The valid password input provided by the user.
-
getValidTypes
Prompts the user to enter a list of types and validates that each type is included in part of the ValidType enum class.- Parameters:
input- The Scanner object used to read user input.prompt- The message displayed to the user when asking for input.- Returns:
- An ArrayList of valid types selected by the user
If any entered type is invalid, the user will be prompted to re-enter the types until all are valid and at least one type is provided.
-
getValidDate
Prompts the user to enter a date and validates that it is in the correct format (MM-dd-yyyy) and that it is not a past date.- Parameters:
input- The Scanner object used to read user input.prompt- The message displayed to the user when asking for input.- Returns:
- The valid LocalDate input provided by the user.
-
getValidTime
Prompts the user to enter a time and validates that it is in the correct format (HH:mm).- Parameters:
input- The Scanner object used to read user input.prompt- The message displayed to the user when asking for input.- Returns:
- The valid LocalTime input provided by the user.
-