Class PatternBasedIpListParser
java.lang.Object
de.gustavblass.nginx.ipguard4j.parser.PatternBasedIpListParser
- All Implemented Interfaces:
IpListParser
A parser for IP-address list entries that uses a regular expression to extract the IP
address.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final @NonNull StringThe name of the capture group in the regular expression that contains the IP address.private final @NonNull PatternThe regular expression that is used to extract the IP address from the list entry. -
Constructor Summary
ConstructorsConstructorDescriptionPatternBasedIpListParser(@NonNull Pattern pattern) Creates a newPatternBasedIpListParserthat uses the given regular expression to extractIPAddresses from entries of an IP list. -
Method Summary
Modifier and TypeMethodDescription@NonNull Optional<inet.ipaddr.IPAddress> Converts the given plain-text entry (in the format defined by the regular expression) of an IP-address list into anIPAddressobject.
-
Field Details
-
IP_ADDRESS_CAPTURE_GROUP_NAME
The name of the capture group in the regular expression that contains the IP address.- See Also:
-
pattern
The regular expression that is used to extract the IP address from the list entry. The IP address must be contained in a capture group with the name specified byIP_ADDRESS_CAPTURE_GROUP_NAME. That capture group must not contain any other characters than the IP address itself.
-
-
Constructor Details
-
PatternBasedIpListParser
public PatternBasedIpListParser(@NonNull @NonNull Pattern pattern) throws de.gustavblass.commons.exceptions.IllegalArgumentException Creates a newPatternBasedIpListParserthat uses the given regular expression to extractIPAddresses from entries of an IP list.- Parameters:
pattern- The regular expression matching each line of the IP list. Must adhere to the requirements ofpattern.- 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 anIPAddressobject.- Specified by:
parsein interfaceIpListParser- Parameters:
listEntry- The string representation of the IP address.- Returns:
- The IP address represented by the given string. Empty
Optionalif 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 anIPAddressobject.
-