Package org.example

Class PhoneStatic

java.lang.Object
org.example.PhoneStatic

public class PhoneStatic extends Object
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 Details

    • FILE_PATH

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

      public static final Pattern REGEX_VALID_PHONE_NUMBER
      Regular expression pattern for valid phone numbers.
  • Method Details

    • readAllLinesAndReturn

      public static List<String> readAllLinesAndReturn()
      Reads all lines from the file specified by 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.
      Returns:
      A List of strings representing the lines from the file.
    • readAllLinesAndReturn

      public static List<String> readAllLinesAndReturn(String filePath)
      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

      public static List<String> removeComments(List<String> lines)
      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

      public static List<String> removeEmptyLines(List<String> lines)
      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

      public static int numberOfLines(List<String> lines)
      Returns the number of lines in the given list.
      Parameters:
      lines - The list of lines.
      Returns:
      The number of lines.
    • isNumberValid

      public static boolean isNumberValid(String number)
      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

      public static int numberOfValidNumbers(List<String> lines)
      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

      public static int numberOfInvalidNumbers(List<String> lines)
      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

      public static List<String> listOfValidNumbers(List<String> lines)
      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.