YANG construct collision detection framework added

Change-Id: I1458f9e3192641f3f90c444798c31a64536ffa5d
diff --git a/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerCollisionDetector.java b/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerCollisionDetector.java
new file mode 100644
index 0000000..7697e6a
--- /dev/null
+++ b/src/main/java/org/onosproject/yangutils/parser/impl/parserutils/ListenerCollisionDetector.java
@@ -0,0 +1,72 @@
+/*
+ * Copyright 2016 Open Networking Laboratory
+ *
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.onosproject.yangutils.parser.impl.parserutils;
+
+import org.onosproject.yangutils.datamodel.CollisionDetector;
+import org.onosproject.yangutils.datamodel.exceptions.DataModelException;
+import org.onosproject.yangutils.parser.exceptions.ParserException;
+import org.onosproject.yangutils.parser.impl.TreeWalkListener;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorLocation.EXIT;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorMessageConstruction.constructListenerErrorMessage;
+import static org.onosproject.yangutils.parser.impl.parserutils.ListenerErrorType.INVALID_HOLDER;
+import org.onosproject.yangutils.utils.YangConstructType;
+
+/**
+ * Check the YANG construct collision in a YANG file.
+ */
+public final class ListenerCollisionDetector {
+
+    /**
+     * Creates a new listener collision.
+     */
+    private ListenerCollisionDetector() {
+    }
+
+    /**
+     * Detects that the identifiers of all these child nodes must be unique
+     * within all cases in a choice.
+     *
+     * @param listener listener's object
+     * @param line line of identifier in YANG file, required for error
+     *            reporting
+     * @param charPosition character position of identifier in YANG file,
+     *            required for error reporting
+     * @param identifierName name for which uniqueness is to be detected
+     * @param constructType type of YANG construct for which collision check is
+     *            to be performed
+     * @throws ParserException if identifier is not unique
+     */
+    public static void detectCollidingChildUtil(TreeWalkListener listener, int line, int charPosition,
+            String identifierName, YangConstructType constructType)
+                    throws ParserException {
+
+        if (listener.getParsedDataStack().peek() instanceof CollisionDetector) {
+            try {
+                ((CollisionDetector) listener.getParsedDataStack().peek()).detectCollidingChild(
+                        identifierName, constructType);
+            } catch (DataModelException e) {
+                ParserException parserException = new ParserException(e.getMessage());
+                parserException.setLine(line);
+                parserException.setCharPosition(charPosition);
+                throw parserException;
+            }
+        } else {
+            throw new ParserException(constructListenerErrorMessage(INVALID_HOLDER, constructType, identifierName,
+                    EXIT));
+        }
+    }
+}