Class IPAddress

java.lang.Object
com.eqixiac.equinix.core.model.IPAddress

public final class IPAddress extends Object
An immutable, typed IP address value, optionally with a CIDR subnet prefix length.

Provided as a type-safe alternative to passing raw IP strings into resource builders (for example Network Edge BGP peering local/remote IPs, VPN peer/tunnel IPs, device system IPs, and route-aggregation prefixes). Construct one from a literal address with parse(String):

IPAddress peer    = IPAddress.parse("203.0.113.10");
IPAddress network = IPAddress.parse("203.0.113.0/24");
String cidr       = network.toCidr();   // "203.0.113.0/24"

parse(String) accepts literals only - a strict IPv4 dotted-quad or an IPv6 address - and never performs a DNS lookup. Hostnames, legacy inet_addr shorthand (e.g. "203.0.113") and malformed addresses are rejected with an EquinixClientException.

Author:
ianjones
  • Method Details

    • parse

      public static IPAddress parse(String value)
      Parses a literal IPv4/IPv6 address, optionally in CIDR form (e.g. "203.0.113.0/24").

      Validation is strict and purely local: IPv4 must be a full dotted-quad (four decimal octets, each 0-255) and IPv6 must be a valid RFC 4291 literal (including :: compression and embedded IPv4 forms). No DNS resolution is ever attempted, so a hostname such as "example.com" fails immediately. When a /<prefixLength> suffix is present it must be within 0-32 for IPv4 or 0-128 for IPv6.

      Parameters:
      value - the literal IP address, optionally suffixed with /<prefixLength>
      Returns:
      a populated IPAddress
      Throws:
      EquinixClientException - if the value is null/blank, not a literal IP address, or has an out-of-range subnet prefix
    • getHostAddress

      public String getHostAddress()
      Returns:
      the numeric host address
    • toString

      public String toString()
      Overrides:
      toString in class Object
    • toCidr

      public String toCidr()
      Returns the address in CIDR notation (host/subnet), or just the host if no subnet is set.
      Returns:
      the CIDR (or host) string
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object