Class PatternBasedIpListParser

java.lang.Object
de.gustavblass.nginx.ipguard4j.parser.PatternBasedIpListParser
All Implemented Interfaces:
IpListParser

public class PatternBasedIpListParser extends Object implements IpListParser
A parser for IP-address list entries that uses a regular expression to extract the IP address.
  • Field Details

  • Constructor Details

    • PatternBasedIpListParser

      public PatternBasedIpListParser(@NonNull @NonNull Pattern pattern) throws de.gustavblass.commons.exceptions.IllegalArgumentException
      Creates a new PatternBasedIpListParser that uses the given regular expression to extract IPAddresses from entries of an IP list.
      Parameters:
      pattern - The regular expression matching each line of the IP list. Must adhere to the requirements of pattern.
      Throws:
      de.gustavblass.commons.exceptions.IllegalArgumentException - If the given pattern does not contain the required capture group for the IP address.
  • Method Details

    • parse

      @Contract(pure=true) @NonNull public @NonNull Optional<inet.ipaddr.IPAddress> parse(@NonNull @NonNull String listEntry) throws de.gustavblass.commons.exceptions.IllegalArgumentException
      Converts the given plain-text entry (in the format defined by the regular expression) of an IP-address list into an IPAddress object.
      Specified by:
      parse in interface IpListParser
      Parameters:
      listEntry - The string representation of the IP address.
      Returns:
      The IP address represented by the given string. Empty Optional if the entry does not match the regular expression.
      Throws:
      de.gustavblass.commons.exceptions.IllegalArgumentException - If the content of the capture group could not be converted into an IPAddress object.