Package org.example
Class PhoneClass
java.lang.Object
org.example.PhoneClass
This class represents a phone number utility.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
isNumberValid
(String number) Checks if a given number matches the REGEX_VALID_PHONE_NUMBER pattern.Returns a list of valid phone numbers from the 'lines' field.int
Returns the number of invalid phone numbers in the 'lines' field.int
Returns the number of lines in the 'lines' field.int
Returns the number of valid phone numbers in the 'lines' field.void
Reads all lines from the file and stores them in the 'lines' field.boolean
Removes lines that start with a hash (#) symbol.boolean
Removes empty lines from the 'lines' field.
-
Field Details
-
lines
List of lines read from the file. -
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
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
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
Returns a list of valid phone numbers from the 'lines' field.- Returns:
- a list of valid phone numbers.
-