IpAddressUtil { public static List<String> ipRange(String ipStr) throws IpAddressException { if (ipStr.contains("-")) { String[] indivIp = ipStr.split("-"); if (indivIp.length != 2) { throw new IpAddressException(String.format("Ip range format is invalid '%s'", ipStr)); } return ipRange(indivIp[0], indivIp[1]); } else { validateFormat(ipStr); ArrayList<String> ips = new ArrayList<>(); ips.add(ipStr.trim()); return ips; } }  static void main(String[] args); static List<String> ipRange(String ipStr); static void validateFormat(String ip); static List<String> ipRange(String srcIp, String destIp); static Pattern IP_PATTERN; }
@Test public void testIpRange() throws IpAddressException { List<String> ipRange = IpAddressUtil.ipRange("192.168.33.11"); Assert.assertTrue(ipRange.size() == 1); Assert.assertTrue(ipRange.contains("192.168.33.11")); ipRange = IpAddressUtil.ipRange("192.168.33.11-192.168.33.13"); Assert.assertTrue(ipRange.size() == 3); Assert.assertTrue(ipRange.contains("192.168.33.11")); Assert.assertTrue(ipRange.contains("192.168.33.12")); Assert.assertTrue(ipRange.contains("192.168.33.13")); ipRange = IpAddressUtil.ipRange("192.168.0.0-192.168.255.255"); Assert.assertTrue(ipRange.size() == 65536); exception.expect(IpAddressException.class); IpAddressUtil.ipRange("192.168.33.11-192.168.33.11"); IpAddressUtil.ipRange("192.168.33.13-192.168.33.11"); }