Class CustomIpAddressFormatter

java.lang.Object
de.gustavblass.nginx.ipguard4j.CustomIpAddressFormatter
All Implemented Interfaces:
IpAddressFormatter

public class CustomIpAddressFormatter extends Object implements IpAddressFormatter
IpAddressFormatter that uses a custom format to convert an IPAddress to some string representation.
  • Field Details

    • format

      @NonNull private final @NonNull List<Function<inet.ipaddr.IPAddress, String>> format
      In the order defined by the List, executing the Functions converts an IPAddress to the desired string representation.
  • Constructor Details

    • CustomIpAddressFormatter

      public CustomIpAddressFormatter(String format) throws de.gustavblass.commons.exceptions.IllegalArgumentException
      Creates a new CustomIpAddressFormatter that turns IPAddresss into the string representation defined by given format.
      Parameters:
      format - Will be parsed to the format. Must contain the $ip substring at least once, as a placeholder for the IPAddress to be filled in.
      Throws:
      de.gustavblass.commons.exceptions.IllegalArgumentException - If the given format string contains no $ip keyword.
  • Method Details

    • format

      @Contract(pure=true) @NonNull public @NonNull String format(@NonNull @NonNull inet.ipaddr.IPAddress ipAddress)
      Converts the given IPAddress to a string representation according to the format previously defined.
      Specified by:
      format in interface IpAddressFormatter
      Parameters:
      ipAddress - The IPAddress to format.
      Returns:
      The formatted string representation of the given IPAddress.
    • parse

      @Contract(pure=true, value="_ -> new") @NonNull public static @NonNull List<Function<inet.ipaddr.IPAddress, String>> parse(@NonNull @NonNull String format) throws de.gustavblass.commons.exceptions.IllegalArgumentException
      Converts the given string format to list of Functions that can be used to format an IPAddress according to the given format, when executed in the correct order.
      Parameters:
      format - Defines how an IPAddress shall be formatted. Must contain the $ip substring at least once, as a placeholder for the IPAddress to be filled in.
      Returns:
      Functions that must be executed in order to format any IPAddress. The functions are pure and can be executed arbitrarily many times.
      Throws:
      de.gustavblass.commons.exceptions.IllegalArgumentException - If the given format string contains no $ip keyword.