ServerUtil { public static boolean isIpv4(String ip) { return Pattern .compile("([1-9]|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])(\\.(\\d|[1-9]\\d|1\\d{2}|2[0-4]\\d|25[0-5])){3}") .matcher(ip).matches(); }  static boolean isIpv4(String ip); static int getNewPort(); @SneakyThrows static int getNewPort(String key); static boolean isPort(int serverPort); static boolean isSocketPort(int serverPort); static boolean checkHostAndPort(String serverHost, int serverPort); static String buildCacheKey(String serverHost, int serverPort);  }
@Test public void testIsIpv4() { assertTrue(ServerUtil.isIpv4("127.0.0.1")); assertTrue(ServerUtil.isIpv4("192.168.1.111")); assertFalse(ServerUtil.isIpv4("99999.99999.99999.00000")); assertFalse(ServerUtil.isIpv4(TestConstants.LOCAL_HOST)); assertFalse(ServerUtil.isIpv4(" ")); }