@Test public void testInvalidAddressFormat() { try { NetworkAddress networkAddress = NetworkAddress.parse("12.96.0/255.255.224.0"); Assert.fail("expected Illegal arguement exception"); } catch (IllegalArgumentException e) { } }
public static NetworkAddress parse(String networkAddress) { NetworkAddress address = null; if (networkAddress != null) { String[] split = networkAddress.split("/"); if (split.length == 2) { byte[] network = parseDottedQuad(split[0]); byte[] netmask = parseDottedQuad(split[1]); address = toNetworkAddress(network, netmask); } else { throw new IllegalArgumentException("Network address must be ip4Address/netMask"); } } return address; }
NetworkAddress { public static NetworkAddress parse(String networkAddress) { NetworkAddress address = null; if (networkAddress != null) { String[] split = networkAddress.split("/"); if (split.length == 2) { byte[] network = parseDottedQuad(split[0]); byte[] netmask = parseDottedQuad(split[1]); address = toNetworkAddress(network, netmask); } else { throw new IllegalArgumentException("Network address must be ip4Address/netMask"); } } return address; } }
NetworkAddress { public static NetworkAddress parse(String networkAddress) { NetworkAddress address = null; if (networkAddress != null) { String[] split = networkAddress.split("/"); if (split.length == 2) { byte[] network = parseDottedQuad(split[0]); byte[] netmask = parseDottedQuad(split[1]); address = toNetworkAddress(network, netmask); } else { throw new IllegalArgumentException("Network address must be ip4Address/netMask"); } } return address; } private  NetworkAddress(byte[] network, byte[] netmask); }
NetworkAddress { public static NetworkAddress parse(String networkAddress) { NetworkAddress address = null; if (networkAddress != null) { String[] split = networkAddress.split("/"); if (split.length == 2) { byte[] network = parseDottedQuad(split[0]); byte[] netmask = parseDottedQuad(split[1]); address = toNetworkAddress(network, netmask); } else { throw new IllegalArgumentException("Network address must be ip4Address/netMask"); } } return address; } private  NetworkAddress(byte[] network, byte[] netmask); @Override String toString(); boolean isAddressInNetwork(String address); static NetworkAddress parse(String networkAddress); static NetworkAddress parseBlock(String networkAddress); static boolean isValidIPAddress(String networkAddress); }
NetworkAddress { public static NetworkAddress parse(String networkAddress) { NetworkAddress address = null; if (networkAddress != null) { String[] split = networkAddress.split("/"); if (split.length == 2) { byte[] network = parseDottedQuad(split[0]); byte[] netmask = parseDottedQuad(split[1]); address = toNetworkAddress(network, netmask); } else { throw new IllegalArgumentException("Network address must be ip4Address/netMask"); } } return address; } private  NetworkAddress(byte[] network, byte[] netmask); @Override String toString(); boolean isAddressInNetwork(String address); static NetworkAddress parse(String networkAddress); static NetworkAddress parseBlock(String networkAddress); static boolean isValidIPAddress(String networkAddress);  }