X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=model%2Fietf%2Fietf-inet-types%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyang%2Fgen%2Fv1%2Furn%2Fietf%2Fparams%2Fxml%2Fns%2Fyang%2Fietf%2Finet%2Ftypes%2Frev100924%2FHostBuilder.java;h=ee92e8051efeb5eb453f2bcd004cc9176698e45f;hb=608ba65d9884ee3f8574e722a85901371108a4c1;hp=3a03087e1a037962f70d0d346b603d88dbc51248;hpb=6ead361308210a0926250900b644efa4e2ddb19b;p=yangtools.git diff --git a/model/ietf/ietf-inet-types/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev100924/HostBuilder.java b/model/ietf/ietf-inet-types/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev100924/HostBuilder.java index 3a03087e1a..ee92e8051e 100644 --- a/model/ietf/ietf-inet-types/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev100924/HostBuilder.java +++ b/model/ietf/ietf-inet-types/src/main/java/org/opendaylight/yang/gen/v1/urn/ietf/params/xml/ns/yang/ietf/inet/types/rev100924/HostBuilder.java @@ -22,15 +22,19 @@ public class HostBuilder { public static Host getDefaultInstance(String defaultValue) { List matchers = new ArrayList<>(); - if (ipv4Pattern.matcher(defaultValue).matches()) { - matchers.add(Ipv4Address.class.getSimpleName()); - } - if (ipv6Pattern1.matcher(defaultValue).matches() && ipv6Pattern2.matcher(defaultValue).matches()) { + if (ipv6Pattern1.matcher(defaultValue).matches() || ipv6Pattern2.matcher(defaultValue).matches()) { matchers.add(Ipv6Address.class.getSimpleName()); } - if (domainPattern.matcher(defaultValue).matches()) { + + // Ipv4 and Domain Name patterns are not exclusive + // Address 127.0.0.1 matches both patterns + // This way Ipv4 address is preferred to domain name + if (ipv4Pattern.matcher(defaultValue).matches()) { + matchers.add(Ipv4Address.class.getSimpleName()); + } else if (domainPattern.matcher(defaultValue).matches()) { matchers.add(DomainName.class.getSimpleName()); } + if (matchers.size() > 1) { throw new IllegalArgumentException("Cannot create Host from " + defaultValue + ". Value is ambigious for " + matchers); @@ -41,7 +45,7 @@ public class HostBuilder { IpAddress ipAddress = new IpAddress(ipv4); return new Host(ipAddress); } - if (ipv6Pattern1.matcher(defaultValue).matches() && ipv6Pattern2.matcher(defaultValue).matches()) { + if (ipv6Pattern1.matcher(defaultValue).matches() || ipv6Pattern2.matcher(defaultValue).matches()) { Ipv6Address ipv6 = new Ipv6Address(defaultValue); IpAddress ipAddress = new IpAddress(ipv6); return new Host(ipAddress);