Class InputValidator

java.lang.Object
theLocalLoop.InputValidator

public class InputValidator extends Object
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.
  • Method Details

    • getValidInt

      public static int getValidInt(Scanner input, String prompt, int min, int max)
      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

      public static double getValidDouble(Scanner input, String prompt)
      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

      public static String getRequiredString(Scanner input, String prompt)
      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

      public static Constants.ValidFormat getValidFormat(Scanner input, String prompt)
      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

      public static String getValidPassword(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.
      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

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

      public static LocalDate getValidDate(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.
      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

      public static LocalTime getValidTime(Scanner input, String prompt)
      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.