Package org.example
Class PhoneStatic
java.lang.Object
org.example.PhoneStatic
This class represents a static utility for handling phone numbers.
It provides methods for reading phone numbers from a file and storing them in a list.
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic boolean
isNumberValid
(String number) Checks if a phone number is valid based on the defined regular expression.listOfValidNumbers
(List<String> lines) Returns a list of valid phone numbers from the given list.static int
numberOfInvalidNumbers
(List<String> lines) Returns the number of invalid phone numbers in the given list.static int
numberOfLines
(List<String> lines) Returns the number of lines in the given list.static int
numberOfValidNumbers
(List<String> lines) Returns the number of valid phone numbers in the given list.Reads all lines from the file specified byFILE_PATH
and returns them as a List.readAllLinesAndReturn
(String filePath) Reads all lines from the specified file path and returns them as a List.removeComments
(List<String> lines) Removes comments (lines starting with "#") from the given list of lines.removeEmptyLines
(List<String> lines) Removes empty lines from the given list of lines.
-
Field Details
-
FILE_PATH
The file path for reading phone numbers.- See Also:
-
REGEX_VALID_PHONE_NUMBER
Regular expression pattern for valid phone numbers.
-
-
Method Details
-
readAllLinesAndReturn
Reads all lines from the file specified byFILE_PATH
and returns them as a List. If an IOException occurs during the reading process, it will be caught and printed to the console. If an IOException occurs, an empty List will be returned.- Returns:
- A List of strings representing the lines from the file.
-
readAllLinesAndReturn
Reads all lines from the specified file path and returns them as a List. If an IOException occurs during the reading process, it will be caught and printed to the console. If an IOException occurs, an empty List will be returned.- Parameters:
filePath
- The path to the file containing phone numbers.- Returns:
- A List of strings representing the lines from the file.
-
removeComments
Removes comments (lines starting with "#") from the given list of lines.- Parameters:
lines
- The list of lines to process.- Returns:
- A filtered list without comments.
-
removeEmptyLines
Removes empty lines from the given list of lines.- Parameters:
lines
- The list of lines to process.- Returns:
- A filtered list without empty lines.
-
numberOfLines
Returns the number of lines in the given list.- Parameters:
lines
- The list of lines.- Returns:
- The number of lines.
-
isNumberValid
Checks if a phone number is valid based on the defined regular expression.- Parameters:
number
- The phone number to validate.- Returns:
- true if the number is valid, false otherwise.
-
numberOfValidNumbers
Returns the number of valid phone numbers in the given list.- Parameters:
lines
- The list of phone numbers.- Returns:
- The count of valid phone numbers.
-
numberOfInvalidNumbers
Returns the number of invalid phone numbers in the given list.- Parameters:
lines
- The list of phone numbers.- Returns:
- The count of invalid phone numbers.
-
listOfValidNumbers
Returns a list of valid phone numbers from the given list.- Parameters:
lines
- The list of phone numbers.- Returns:
- A list of valid phone numbers.
-