[ONOS-3894, 4071] YANG Advanced Construct Union & Grouping

Change-Id: I0f828adb5884c2d7b6e4120f9843c416608ae5e7
diff --git a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java
index c61ce80..05e9c28 100644
--- a/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java
+++ b/utils/yangutils/src/main/java/org/onosproject/yangutils/datamodel/YangUnion.java
@@ -20,6 +20,7 @@
 import org.onosproject.yangutils.parser.Parsable;
 import org.onosproject.yangutils.utils.YangConstructType;
 
+import java.util.LinkedList;
 import java.util.List;
 
 /*
@@ -52,13 +53,14 @@
     // List of YANG type.
     private List<YangType<?>> typeList;
 
-    // Name of the union.
+    // Name of union.
     private String unionName;
 
     /**
      * Create a YANG union node.
      */
     public YangUnion() {
+        typeList = new LinkedList<>();
     }
 
     /**
@@ -89,6 +91,21 @@
     }
 
     /**
+     * Add YANG type to type list.
+     *
+     * @param yangType YANG type to be added to list
+     * @throws DataModelException union member type must not be one of the
+     * built-in types "empty" or "leafref"
+     */
+    public void addToTypeList(YangType<?> yangType) throws DataModelException {
+        if (yangType.getDataType() == YangDataTypes.EMPTY || yangType.getDataType() == YangDataTypes.LEAFREF) {
+            throw new DataModelException("Union member type must not be one of the built-in types \"empty\" or " +
+                    "\"leafref\"");
+        }
+        getTypeList().add(yangType);
+    }
+
+    /**
      * Set the union name.
      *
      * @param unionName name of the union.