HoneyNode Java 11 support for 221 devices
[transportpce.git] / tests / honeynode / 2.2.1 / honeynode-plugin-api / src / main / java / org / opendaylight / yang / gen / v1 / urn / ietf / params / xml / ns / yang / ietf / inet / types / rev130715 / IpAddressBuilder.java
index 148b59c0c6b398a9010bd0f899b36189fc159154..bbd6352afd877425906f922e3a5cfdb7305c0f9c 100644 (file)
@@ -1,18 +1,45 @@
+
 package org.opendaylight.yang.gen.v1.urn.ietf.params.xml.ns.yang.ietf.inet.types.rev130715;
 
+import java.util.regex.Matcher;
+import java.util.regex.Pattern;
+
 /**
- * The purpose of generated class in src/main/java for Union types is to create new instances of unions from a string representation.
- * In some cases it is very difficult to automate it since there can be unions such as (uint32 - uint16), or (string - uint32).
- *
- * The reason behind putting it under src/main/java is:
- * This class is generated in form of a stub and needs to be finished by the user. This class is generated only once to prevent
- * loss of user code.
- *
+ * * The purpose of generated class in src/main/java for Union types is to
+ * create * new instances of unions from a string representation. In some cases
+ * it is * very difficult to automate it since there can be unions such as
+ * (uint32 - * uint16), or (string - uint32). * * The reason behind putting it
+ * under src/main/java is: This class is generated * in form of a stub and needs
+ * to be finished by the user. This class is * generated only once to prevent
+ * loss of user code. *
  */
 public class IpAddressBuilder {
+    private static final Pattern IPV4_PATTERN = Pattern.compile(
+            "(([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])\\.){3}([0-9]|[1-9][0-9]|1[0-9][0-9]|2[0-4][0-9]|25[0-5])(%[\\p{N}\\p{L}]+)?");
+    private static final Pattern IPV6_PATTERN1 = Pattern.compile(
+            "((:|[0-9a-fA-F]{0,4}):)([0-9a-fA-F]{0,4}:){0,5}((([0-9a-fA-F]{0,4}:)?(:|[0-9a-fA-F]{0,4}))|(((25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])\\.){3}(25[0-5]|2[0-4][0-9]|[01]?[0-9]?[0-9])))(%[\\p{N}\\p{L}]+)?");
+    private static final Pattern IPV6_PATTERN2 = Pattern
+            .compile("(([^:]+:){6}(([^:]+:[^:]+)|(.*\\..*)))|((([^:]+:)*[^:]+)?::(([^:]+:)*[^:]+)?)(%.+)?");
 
-    public static IpAddress getDefaultInstance(java.lang.String defaultValue) {
-        throw new java.lang.UnsupportedOperationException("Not yet implemented");
+    private IpAddressBuilder() {
     }
 
+    /*
+     * * public static IpAddress getDefaultInstance(java.lang.String defaultValue) {
+     * * throw new java.lang.UnsupportedOperationException("Not yet implemented"); }
+     */ public static IpAddress getDefaultInstance(String defaultValue) {
+        final Matcher ipv4Matcher = IPV4_PATTERN.matcher(defaultValue);
+        if (ipv4Matcher.matches()) {
+            if (IPV6_PATTERN1.matcher(defaultValue).matches() && IPV6_PATTERN2.matcher(defaultValue).matches()) {
+                throw new IllegalArgumentException(
+                        String.format("Cannot create IpAddress from \"%s\", matches both %s and %s", defaultValue,
+                                Ipv4Address.class.getSimpleName(), Ipv6Address.class.getSimpleName()));
+            }
+            return new IpAddress(new Ipv4Address(defaultValue));
+        } else if (IPV6_PATTERN1.matcher(defaultValue).matches() && IPV6_PATTERN2.matcher(defaultValue).matches()) {
+            return new IpAddress(new Ipv6Address(defaultValue));
+        } else {
+            throw new IllegalArgumentException("Cannot create IpAddress from " + defaultValue);
+        }
+    }
 }