Class IpAddressSupport

java.lang.Object
edu.cnu.mdi.component.IpAddressSupport

public final class IpAddressSupport extends Object
Validation and matching support for IPv4 addresses with optional wildcard octets.
  • Field Details

    • ANY_ADDRESS

      public static final String ANY_ADDRESS
      See Also:
    • BASIC_PATTERN

      public static final Pattern BASIC_PATTERN
    • SIMPLE_STAR_PATTERN

      public static final Pattern SIMPLE_STAR_PATTERN
  • Method Details

    • validate

      public static boolean validate(String ipAddress)
      Tests whether a string is a literal IPv4 address (no wildcards).
      Parameters:
      ipAddress - the string to test; null is not valid
      Returns:
      true if ipAddress is four dot-separated octets, each in [0, 255]
    • validateSimpleWildcard

      public static boolean validateSimpleWildcard(String ipPattern)
      Tests whether a string is a valid IPv4 address pattern, where each octet is either a literal [0, 255] value or a * wildcard (e.g. "129.57.*.*", or ANY_ADDRESS).
      Parameters:
      ipPattern - the string to test; null is not valid
      Returns:
      true if every octet is a literal byte value or *
    • createPattern

      public static Pattern createPattern(String filterString)
      Compiles a wildcard IPv4 address pattern into a matching Pattern.

      Returns null in two distinct cases that callers may need to tell apart: filterString is null or equals ANY_ADDRESS (meaning "match everything," so no filtering pattern is needed at all), or filterString fails validateSimpleWildcard(java.lang.String) (meaning the input itself is invalid). Either way, treat a null result as "no filter to apply" unless you specifically need to distinguish "no filter requested" from "invalid filter" — this method does not let you tell them apart.

      Parameters:
      filterString - the wildcard address pattern to compile, or null/ANY_ADDRESS for no filtering
      Returns:
      a Pattern matching literal IPv4 addresses consistent with the wildcard pattern, or null (see above)