@Test public void testGetDefaultInstance() throws Exception { final Constructor<HostBuilder> constructor = HostBuilder.class.getDeclaredConstructor(); assertFalse(constructor.isAccessible()); constructor.setAccessible(true); final HostBuilder newInstance = constructor.newInstance(); assertNotNull(newInstance); testIpv4("1.1.1.1"); testIpv4("192.168.155.100"); testIpv4("1.192.1.221"); testIpv6("ABCD:EF01:2345:6789:ABCD:EF01:2345:6789"); testIpv6("2001:DB8:0:0:8:800:200C:417A"); testIpv6("0:0:0:0:0:0:0:0"); testIpv6("::1.2.3.4"); testIpv6("ABCD:EF01:2345:6789:ABCD:EF01:2345:6789"); testIpv6("2001:DB8:0:0:8:800:200C:417A"); testIpv6("2001:DB8::8:800:200C:417A"); testIpv6("FF01:0:0:0:0:0:0:101"); testIpv6("FF01::101"); testIpv6("0:0:0:0:0:0:0:1"); testIpv6("::1"); testIpv6("::"); testDomain("test.domainName.org"); testDomain("domainName.test"); testDomain("test"); }
public static Host getDefaultInstance(final String defaultValue) { final Matcher ipv4Matcher = IPV4_PATTERN.matcher(defaultValue); final Matcher ipv6Matcher1 = IPV6_PATTERN1.matcher(defaultValue); final Matcher ipv6Matcher2 = IPV6_PATTERN2.matcher(defaultValue); final Matcher domainMatcher = DOMAIN_PATTERN.matcher(defaultValue); List<String> matchers = new ArrayList<>(3); if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) { matchers.add(Ipv6Address.class.getSimpleName()); } if (ipv4Matcher.matches()) { matchers.add(Ipv4Address.class.getSimpleName()); } else if (domainMatcher.matches()) { matchers.add(DomainName.class.getSimpleName()); } if (matchers.size() > 1) { throw new IllegalArgumentException("Cannot create Host from " + defaultValue + ". Value is ambigious for " + matchers); } if (ipv4Matcher.matches()) { Ipv4Address ipv4 = new Ipv4Address(defaultValue); IpAddress ipAddress = new IpAddress(ipv4); return new Host(ipAddress); } if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) { Ipv6Address ipv6 = new Ipv6Address(defaultValue); IpAddress ipAddress = new IpAddress(ipv6); return new Host(ipAddress); } if (domainMatcher.matches()) { DomainName domainName = new DomainName(defaultValue); return new Host(domainName); } throw new IllegalArgumentException("Cannot create Host from " + defaultValue); }
HostBuilder { public static Host getDefaultInstance(final String defaultValue) { final Matcher ipv4Matcher = IPV4_PATTERN.matcher(defaultValue); final Matcher ipv6Matcher1 = IPV6_PATTERN1.matcher(defaultValue); final Matcher ipv6Matcher2 = IPV6_PATTERN2.matcher(defaultValue); final Matcher domainMatcher = DOMAIN_PATTERN.matcher(defaultValue); List<String> matchers = new ArrayList<>(3); if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) { matchers.add(Ipv6Address.class.getSimpleName()); } if (ipv4Matcher.matches()) { matchers.add(Ipv4Address.class.getSimpleName()); } else if (domainMatcher.matches()) { matchers.add(DomainName.class.getSimpleName()); } if (matchers.size() > 1) { throw new IllegalArgumentException("Cannot create Host from " + defaultValue + ". Value is ambigious for " + matchers); } if (ipv4Matcher.matches()) { Ipv4Address ipv4 = new Ipv4Address(defaultValue); IpAddress ipAddress = new IpAddress(ipv4); return new Host(ipAddress); } if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) { Ipv6Address ipv6 = new Ipv6Address(defaultValue); IpAddress ipAddress = new IpAddress(ipv6); return new Host(ipAddress); } if (domainMatcher.matches()) { DomainName domainName = new DomainName(defaultValue); return new Host(domainName); } throw new IllegalArgumentException("Cannot create Host from " + defaultValue); } }
HostBuilder { public static Host getDefaultInstance(final String defaultValue) { final Matcher ipv4Matcher = IPV4_PATTERN.matcher(defaultValue); final Matcher ipv6Matcher1 = IPV6_PATTERN1.matcher(defaultValue); final Matcher ipv6Matcher2 = IPV6_PATTERN2.matcher(defaultValue); final Matcher domainMatcher = DOMAIN_PATTERN.matcher(defaultValue); List<String> matchers = new ArrayList<>(3); if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) { matchers.add(Ipv6Address.class.getSimpleName()); } if (ipv4Matcher.matches()) { matchers.add(Ipv4Address.class.getSimpleName()); } else if (domainMatcher.matches()) { matchers.add(DomainName.class.getSimpleName()); } if (matchers.size() > 1) { throw new IllegalArgumentException("Cannot create Host from " + defaultValue + ". Value is ambigious for " + matchers); } if (ipv4Matcher.matches()) { Ipv4Address ipv4 = new Ipv4Address(defaultValue); IpAddress ipAddress = new IpAddress(ipv4); return new Host(ipAddress); } if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) { Ipv6Address ipv6 = new Ipv6Address(defaultValue); IpAddress ipAddress = new IpAddress(ipv6); return new Host(ipAddress); } if (domainMatcher.matches()) { DomainName domainName = new DomainName(defaultValue); return new Host(domainName); } throw new IllegalArgumentException("Cannot create Host from " + defaultValue); } private  HostBuilder(); }
HostBuilder { public static Host getDefaultInstance(final String defaultValue) { final Matcher ipv4Matcher = IPV4_PATTERN.matcher(defaultValue); final Matcher ipv6Matcher1 = IPV6_PATTERN1.matcher(defaultValue); final Matcher ipv6Matcher2 = IPV6_PATTERN2.matcher(defaultValue); final Matcher domainMatcher = DOMAIN_PATTERN.matcher(defaultValue); List<String> matchers = new ArrayList<>(3); if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) { matchers.add(Ipv6Address.class.getSimpleName()); } if (ipv4Matcher.matches()) { matchers.add(Ipv4Address.class.getSimpleName()); } else if (domainMatcher.matches()) { matchers.add(DomainName.class.getSimpleName()); } if (matchers.size() > 1) { throw new IllegalArgumentException("Cannot create Host from " + defaultValue + ". Value is ambigious for " + matchers); } if (ipv4Matcher.matches()) { Ipv4Address ipv4 = new Ipv4Address(defaultValue); IpAddress ipAddress = new IpAddress(ipv4); return new Host(ipAddress); } if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) { Ipv6Address ipv6 = new Ipv6Address(defaultValue); IpAddress ipAddress = new IpAddress(ipv6); return new Host(ipAddress); } if (domainMatcher.matches()) { DomainName domainName = new DomainName(defaultValue); return new Host(domainName); } throw new IllegalArgumentException("Cannot create Host from " + defaultValue); } private  HostBuilder(); static Host getDefaultInstance(final String defaultValue); }
HostBuilder { public static Host getDefaultInstance(final String defaultValue) { final Matcher ipv4Matcher = IPV4_PATTERN.matcher(defaultValue); final Matcher ipv6Matcher1 = IPV6_PATTERN1.matcher(defaultValue); final Matcher ipv6Matcher2 = IPV6_PATTERN2.matcher(defaultValue); final Matcher domainMatcher = DOMAIN_PATTERN.matcher(defaultValue); List<String> matchers = new ArrayList<>(3); if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) { matchers.add(Ipv6Address.class.getSimpleName()); } if (ipv4Matcher.matches()) { matchers.add(Ipv4Address.class.getSimpleName()); } else if (domainMatcher.matches()) { matchers.add(DomainName.class.getSimpleName()); } if (matchers.size() > 1) { throw new IllegalArgumentException("Cannot create Host from " + defaultValue + ". Value is ambigious for " + matchers); } if (ipv4Matcher.matches()) { Ipv4Address ipv4 = new Ipv4Address(defaultValue); IpAddress ipAddress = new IpAddress(ipv4); return new Host(ipAddress); } if (ipv6Matcher1.matches() || ipv6Matcher2.matches()) { Ipv6Address ipv6 = new Ipv6Address(defaultValue); IpAddress ipAddress = new IpAddress(ipv6); return new Host(ipAddress); } if (domainMatcher.matches()) { DomainName domainName = new DomainName(defaultValue); return new Host(domainName); } throw new IllegalArgumentException("Cannot create Host from " + defaultValue); } private  HostBuilder(); static Host getDefaultInstance(final String defaultValue);  }