Class PlainIpListParser

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

public class PlainIpListParser extends Object implements IpListParser
A parser that extracts IPAddresses from plain IP-list entries, without special formatting (other than comments).
  • Field Details

    • DEFAULT_COMMENT_CHARACTERS

      @NonNull private static final @NonNull HashSet<Character> DEFAULT_COMMENT_CHARACTERS
      Pre-defined symbols that mark the beginning of a comment in a plain IP-list entry. The character itself and everything after it will be ignored when parsing the entry.
    • commentCharacters

      @NonNull private final @NonNull HashSet<Character> commentCharacters
      Symbols that mark the beginning of a comment in a plain IP-list entry. The character itself and everything after it will be ignored when parsing the entry.
  • Constructor Details

    • PlainIpListParser

      public PlainIpListParser()
  • 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 of an IP-address list into an IPAddress object.
      Specified by:
      parse in interface IpListParser
      Parameters:
      listEntry - The string representation of the IP address, in plain format. Comments starting with any of the commentCharacters will be ignored.
      Returns:
      The IP address represented by the given string. Empty if no entry is blank or contains only a comment.
      Throws:
      de.gustavblass.commons.exceptions.IllegalArgumentException - If the non-blank, non-comment part of the given string does not represent a valid IP address.
    • hashCode

      @Contract(pure=true) public int hashCode()
      Overrides:
      hashCode in class Object
      Returns:
      The AbstractSet.hashCode() of the commentCharacters.
    • builder

      @Contract(pure=true, value="-> new") @NonNull public static @NonNull PlainIpListParser.StartBuilder builder()

      Visual representation of the builder grammar below

      Builder ::= ( '#withDefaultCommentSymbols' | '#withoutDefaultCommentSymbols' )
                  '#addCommentSymbol'* 
                  '#build'
      
      Returns:
      A new builder for creating a new PlainIpListParser instance.