[ONOS-4070] Translator of YANG union.

Change-Id: I5216687b6ea7cb6baeb3ef8e905719468370a1f4
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
index 3548b43..db3ff8f 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/UtilConstants.java
@@ -34,18 +34,18 @@
     /**
      * JavaDocs for impl class.
      */
-    public static final String IMPL_CLASS_JAVA_DOC = " * Reperesents the implementation of ";
+    public static final String IMPL_CLASS_JAVA_DOC = " * Represents the implementation of ";
 
     /**
      * JavaDocs for builder class.
      */
-    public static final String BUILDER_CLASS_JAVA_DOC = " * Reperesents the builder implementation of ";
+    public static final String BUILDER_CLASS_JAVA_DOC = " * Represents the builder implementation of ";
 
     /**
      * JavaDocs for interface class.
      */
-    public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which Reperesents the"
-            + " functionalities of ";
+    public static final String INTERFACE_JAVA_DOC = " * Abstraction of an entity which represents the"
+            + " functionality of ";
 
     /**
      * JavaDocs for builder interface class.
@@ -148,6 +148,31 @@
     public static final String PERIOD = ".";
 
     /**
+     * Static attribute for parse byte.
+     */
+    public static final String PARSE_BYTE = "parseByte";
+
+    /**
+     * Static attribute for parse short.
+     */
+    public static final String PARSE_SHORT = "parseShort";
+
+    /**
+     * Static attribute for parse int.
+     */
+    public static final String PARSE_INT = "parseInt";
+
+    /**
+     * Static attribute for parse long.
+     */
+    public static final String PARSE_LONG = "parseLong";
+
+    /**
+     * Static attribute for omit null value.
+     */
+    public static final String OMIT_NULL_VALUE_STRING = "omitNullValues()";
+
+    /**
      * Static attribute for colan.
      */
     public static final String COLAN = ":";
@@ -173,9 +198,9 @@
     public static final String SPACE = " ";
 
     /**
-     * Static attribute for tab.
+     * Static attribute for input string.
      */
-    public static final String TAB = "\t";
+    public static final String INPUT = "input";
 
     /**
      * Static attribute for new line.
@@ -223,6 +248,11 @@
     public static final String ADD_STRING = "add";
 
     /**
+     * Static attribute for from syntax.
+     */
+    public static final String FROM_STRING_METHOD_NAME = "fromString";
+
+    /**
      * Static attribute for check not null syntax.
      */
     public static final String CHECK_NOT_NULL_STRING = "checkNotNull";
@@ -333,14 +363,14 @@
     public static final String DIAMOND_CLOSE_BRACKET = ">";
 
     /**
-     * Static attribute for square open bracket syntax.
+     * Static attribute for exception syntax.
      */
-    public static final String SQUARE_OPEN_BRACKET = "[";
+    public static final String EXCEPTION = "Exception";
 
     /**
-     * Static attribute for square close bracket syntax.
+     * Static attribute for exception variable syntax.
      */
-    public static final String SQUARE_CLOSE_BRACKET = "]";
+    public static final String EXCEPTION_VAR = "e";
 
     /**
      * Static attribute for open parenthesis syntax.
@@ -348,6 +378,21 @@
     public static final String OPEN_PARENTHESIS = "(";
 
     /**
+     * Static attribute for clear syntax.
+     */
+    public static final String CLEAR = "clear";
+
+    /**
+     * Static attribute for temp val syntax.
+     */
+    public static final String TMP_VAL = "tmpVal";
+
+    /**
+     * From string parameter name.
+     */
+    public static final String FROM_STRING_PARAM_NAME = "valInString";
+
+    /**
      * Static attribute for close parenthesis syntax.
      */
     public static final String CLOSE_PARENTHESIS = ")";
@@ -378,6 +423,21 @@
     public static final String FOUR_SPACE_INDENTATION = "    ";
 
     /**
+     * Static attribute for not syntax.
+     */
+    public static final String NOT = "!";
+
+    /**
+     * Static attribute for try syntax.
+     */
+    public static final String TRY = "try";
+
+    /**
+     * Static attribute for catch syntax.
+     */
+    public static final String CATCH = "catch";
+
+    /**
      * Static attribute for eight space indentation.
      */
     public static final String EIGHT_SPACE_INDENTATION = FOUR_SPACE_INDENTATION + FOUR_SPACE_INDENTATION;
@@ -518,14 +578,9 @@
     public static final String LONG_WRAPPER = "Long";
 
     /**
-     * Float java built in wrapper type.
+     * YangUint64 java built in wrapper type.
      */
-    public static final String FLOAT_WRAPPER = "Float";
-
-    /**
-     * Double java built in wrapper type.
-     */
-    public static final String DOUBLE_WRAPPER = "Double";
+    public static final String YANG_UINT64 = "YangUint64";
 
     /**
      * List of keywords in java, this is used for checking if the input does not contain these keywords.
@@ -733,92 +788,12 @@
     public static final String AUGMENTED_INFO = "AugmentedInfo";
 
     /**
-     * Static attribute for abstract collection.
-     */
-    public static final String ABSTRACT_COLLECTION = "AbstractCollection";
-
-    /**
      * Static attribute for list.
      */
     public static final String LIST = "List";
 
     /**
-     * Static attribute for linked list.
-     */
-    public static final String LINKED_LIST = "LinkedList";
-
-    /**
      * Static attribute for array list.
      */
     public static final String ARRAY_LIST = "ArrayList";
-
-    /**
-     * Static attribute for abstract list.
-     */
-    public static final String ABSTRACT_LIST = "AbstractList";
-
-    /**
-     * Static attribute for abstract sequential list.
-     */
-    public static final String ABSTRACT_SEQUENTAIL_LIST = "AbstractSequentialList";
-
-    /**
-     * Static attribute for set.
-     */
-    public static final String SET = "Set";
-
-    /**
-     * Static attribute for hash set.
-     */
-    public static final String HASH_SET = "HashSet";
-
-    /**
-     * Static attribute for abstract set.
-     */
-    public static final String ABSTRACT_SET = "AbstractSet";
-
-    /**
-     * Static attribute for linked has set.
-     */
-    public static final String LINKED_HASH_SET = "LinkedHashSet";
-
-    /**
-     * Static attribute for tree set.
-     */
-    public static final String TREE_SET = "TreeSet";
-
-    /**
-     * Static attribute for map.
-     */
-    public static final String MAP = "Map";
-
-    /**
-     * Static attribute for abstract map.
-     */
-    public static final String ABSTRACT_MAP = "AbstractMap";
-
-    /**
-     * Static attribute for hash map.
-     */
-    public static final String HASH_MAP = "HashMap";
-
-    /**
-     * Static attribute for tree map.
-     */
-    public static final String TREE_MAP = "TreeMap";
-
-    /**
-     * Static attribute for concurrent map.
-     */
-    public static final String CONCURRENT_MAP = "ConcurrentMap";
-
-    /**
-     * Static attribute for eventually consistent map.
-     */
-    public static final String EVENTUALLY_CONSISTENT_MAP = "EventuallyConsitentMap";
-
-    /**
-     * Static attribute for stack syntax.
-     */
-    public static final String STACK = "stack";
 }
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
index c76ecad..a1cae8e 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/utils/io/impl/JavaDocGen.java
@@ -23,8 +23,11 @@
 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_INTERFACE_JAVA_DOC;
 import static org.onosproject.yangutils.utils.UtilConstants.BUILDER_OBJECT;
 import static org.onosproject.yangutils.utils.UtilConstants.FOUR_SPACE_INDENTATION;
+import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_METHOD_NAME;
+import static org.onosproject.yangutils.utils.UtilConstants.FROM_STRING_PARAM_NAME;
 import static org.onosproject.yangutils.utils.UtilConstants.IMPL;
 import static org.onosproject.yangutils.utils.UtilConstants.IMPL_CLASS_JAVA_DOC;
+import static org.onosproject.yangutils.utils.UtilConstants.INPUT;
 import static org.onosproject.yangutils.utils.UtilConstants.INTERFACE_JAVA_DOC;
 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD;
 import static org.onosproject.yangutils.utils.UtilConstants.JAVA_DOC_BUILD_RETURN;
@@ -45,6 +48,7 @@
 import static org.onosproject.yangutils.utils.UtilConstants.PACKAGE_INFO_JAVADOC;
 import static org.onosproject.yangutils.utils.UtilConstants.PERIOD;
 import static org.onosproject.yangutils.utils.UtilConstants.SPACE;
+import static org.onosproject.yangutils.utils.UtilConstants.STRING_DATA_TYPE;
 import static org.onosproject.yangutils.utils.UtilConstants.VALUE;
 
 /**
@@ -104,11 +108,6 @@
         TYPE_DEF_SETTER_METHOD,
 
         /**
-         * For type def's constructor.
-         */
-        TYPE_DEF_CONSTRUCTOR,
-
-        /**
          * For of method.
          */
         OF_METHOD,
@@ -124,6 +123,16 @@
         CONSTRUCTOR,
 
         /**
+         * For union's from method.
+         */
+        UNION_FROM_METHOD,
+
+        /**
+         * For type constructor.
+         */
+        TYPE_CONSTRUCTOR,
+
+        /**
          * For build.
          */
         BUILD_METHOD
@@ -132,8 +141,8 @@
     /**
      * Returns java docs.
      *
-     * @param type java doc type
-     * @param name name of the YangNode
+     * @param type   java doc type
+     * @param name   name of the YangNode
      * @param isList is list attribute
      * @return javadocs.
      */
@@ -155,8 +164,6 @@
             javaDoc = generateForGetters(name, isList);
         } else if (type.equals(JavaDocType.TYPE_DEF_SETTER_METHOD)) {
             javaDoc = generateForTypeDefSetter(name);
-        } else if (type.equals(JavaDocType.TYPE_DEF_CONSTRUCTOR)) {
-            javaDoc = generateForTypeDefConstructor(name);
         } else if (type.equals(JavaDocType.SETTER_METHOD)) {
             javaDoc = generateForSetters(name, isList);
         } else if (type.equals(JavaDocType.OF_METHOD)) {
@@ -165,6 +172,10 @@
             javaDoc = generateForDefaultConstructors(name);
         } else if (type.equals(JavaDocType.BUILD_METHOD)) {
             javaDoc = generateForBuild(name);
+        } else if (type.equals(JavaDocType.TYPE_CONSTRUCTOR)) {
+            javaDoc = generateForTypeConstructor(name);
+        } else if (type.equals(JavaDocType.UNION_FROM_METHOD)) {
+            javaDoc = generateForUnionFrom(name);
         } else {
             javaDoc = generateForConstructors(name);
         }
@@ -175,7 +186,7 @@
      * Generate javaDocs for getter method.
      *
      * @param attribute attribute
-     * @param isList is list attribute
+     * @param isList    is list attribute
      * @return javaDocs
      */
     private static String generateForGetters(String attribute, boolean isList) {
@@ -198,7 +209,7 @@
      * Generates javaDocs for setter method.
      *
      * @param attribute attribute
-     * @param isList is list attribute
+     * @param isList    is list attribute
      * @return javaDocs
      */
     private static String generateForSetters(String attribute, boolean isList) {
@@ -232,6 +243,22 @@
     }
 
     /**
+     * Generates javaDocs for from method.
+     *
+     * @param attribute attribute
+     * @return javaDocs
+     */
+    private static String generateForUnionFrom(String attribute) {
+
+        return NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_OF
+                + attribute + SPACE + FROM_STRING_METHOD_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + PERIOD
+                + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION + JAVA_DOC_PARAM
+                + FROM_STRING_PARAM_NAME + SPACE + INPUT + SPACE + STRING_DATA_TYPE + PERIOD + NEW_LINE
+                + FOUR_SPACE_INDENTATION + JAVA_DOC_RETURN + OBJECT + SPACE + OF + SPACE + attribute + NEW_LINE
+                + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE;
+    }
+
+    /**
      * Generates javaDocs for typedef setter method.
      *
      * @param attribute attribute
@@ -347,4 +374,18 @@
                 + JAVA_DOC_RETURN + JAVA_DOC_BUILD_RETURN + buildName + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION
                 + JAVA_DOC_END_LINE;
     }
+
+    /**
+     * Generates javaDocs for type constructor.
+     *
+     * @param attribute attribute string
+     * @return javaDocs for type constructor
+     */
+    private static String generateForTypeConstructor(String attribute) {
+
+        return (NEW_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_FIRST_LINE + FOUR_SPACE_INDENTATION + JAVA_DOC_CONSTRUCTOR
+                + attribute + PERIOD + NEW_LINE + FOUR_SPACE_INDENTATION + NEW_LINE_ASTERISK + FOUR_SPACE_INDENTATION
+                + JAVA_DOC_PARAM + VALUE + SPACE + VALUE + SPACE + OF + SPACE + attribute + NEW_LINE
+                + FOUR_SPACE_INDENTATION + JAVA_DOC_END_LINE);
+    }
 }