/** * Create an {@link IpNetwork} instance which represents the IP network * specified by CIDR notation. * * @param cidr A string representation of the IP network in CIDR notation. * Note that zero prefix means "no mask". So zero prefix is * treated as if the maximum prefix length is specified. * @return An {@link IpNetwork} instance which represents the IP network * specified by {@code cidr}. Note that {@code null} is returned * if {@code cidr} is {@code null}. * @throws IllegalArgumentException * The given network address is invalid. */ public static final IpNetwork create(String cidr) { if (cidr == null) { return null; } InetAddressPrefix ipfx = new InetAddressPrefix(cidr); return create(ipfx.getAddress(), ipfx.getPrefix()); }
/** * Set the IP network address by a string representation of network address * in CIDR notation. * * @param cidr A string representation of this network address. * @throws NullPointerException * {@code cidr} is {@code null}. * @throws IllegalArgumentException * The given network address or prefix length is invalid. */ private void setCidrValue(String cidr) { InetAddressPrefix ipfx = new InetAddressPrefix(cidr); int prefix = ipfx.getPrefix(); if (prefix == 0) { prefix = getMaxPrefix(); } inetAddress = init(ipfx.getAddress(), prefix); prefixLength = prefix; }