Package org.example

Class PhoneClass

java.lang.Object
org.example.PhoneClass

public class PhoneClass extends Object
This class represents a phone number utility.
  • Field Details

    • lines

      public List<String> lines
      List of lines read from the file.
    • REGEX_VALID_PHONE_NUMBER

      public static final Pattern REGEX_VALID_PHONE_NUMBER
      Regular expression pattern to validate phone numbers. Matches US phone numbers in the following formats: (123) 456-7890, 123 456 7890, 123-456-7890
    • FILE_PATH

      public static final String FILE_PATH
      The file path for reading phone numbers.
      See Also:
  • Method Details

    • readAllLinesAndStoreInField

      public void readAllLinesAndStoreInField()
      Reads all lines from the file and stores them in the 'lines' field.
    • removeComments

      public boolean removeComments()
      Removes lines that start with a hash (#) symbol.
      Returns:
      true if any comments are removed, false otherwise.
    • removeEmptyLines

      public boolean removeEmptyLines()
      Removes empty lines from the 'lines' field.
      Returns:
      true if any empty lines are removed, false otherwise.
    • numberOfLines

      public int numberOfLines()
      Returns the number of lines in the 'lines' field.
      Returns:
      the number of lines.
    • isNumberValid

      public boolean isNumberValid(String number)
      Checks if a given number matches the REGEX_VALID_PHONE_NUMBER pattern.
      Parameters:
      number - the phone number to validate.
      Returns:
      true if the number is valid, false otherwise.
    • numberOfValidNumbers

      public int numberOfValidNumbers()
      Returns the number of valid phone numbers in the 'lines' field.
      Returns:
      the number of valid phone numbers.
    • numberOfInvalidNumbers

      public int numberOfInvalidNumbers()
      Returns the number of invalid phone numbers in the 'lines' field.
      Returns:
      the number of invalid phone numbers.
    • listOfValidNumbers

      public List<String> listOfValidNumbers()
      Returns a list of valid phone numbers from the 'lines' field.
      Returns:
      a list of valid phone numbers.