Merge "Updated creation of Binding Spec Context to provide additional information."
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / NodeUtils.java
index 31ab5fdbb2b0f42e822fc7080add4b2f83b404e3..bc05425c9aa46c607297bc996749d7a7141f8d61 100644 (file)
@@ -7,12 +7,19 @@
  */
 package org.opendaylight.yangtools.yang.data.impl;
 
+import com.google.common.base.Function;
+import com.google.common.base.Joiner;
+import com.google.common.collect.Iterables;
+import com.google.common.collect.Lists;
+import com.google.common.collect.Maps;
+
 import java.util.AbstractMap.SimpleEntry;
+import java.util.ArrayDeque;
 import java.util.ArrayList;
+import java.util.Deque;
 import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.Stack;
 
 import javax.xml.parsers.DocumentBuilder;
 import javax.xml.parsers.DocumentBuilderFactory;
@@ -37,17 +44,19 @@ import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 import org.w3c.dom.Element;
 
-import com.google.common.base.Joiner;
-import com.google.common.collect.Lists;
-import com.google.common.collect.Maps;
-
 /**
  * @author michal.rehak
  *
  */
 public abstract class NodeUtils {
-
+    private static final Joiner DOT_JOINER = Joiner.on(".");
     private static final Logger LOG = LoggerFactory.getLogger(NodeUtils.class);
+    private static final Function<QName, String> LOCALNAME_FUNCTION = new Function<QName, String>() {
+        @Override
+        public String apply(final QName input) {
+            return input.getLocalName();
+        }
+    };
 
     /**
      *
@@ -66,7 +75,7 @@ public abstract class NodeUtils {
             tmpNode = tmpNode.getParent();
         }
 
-        return Joiner.on(".").join(breadCrumbs);
+        return DOT_JOINER.join(breadCrumbs);
     }
 
     /**
@@ -85,7 +94,7 @@ public abstract class NodeUtils {
             return null;
         }
 
-        Stack<SimpleEntry<org.w3c.dom.Node, Node<?>>> jobQueue = new Stack<>();
+        final Deque<SimpleEntry<org.w3c.dom.Node, Node<?>>> jobQueue = new ArrayDeque<>();
         jobQueue.push(new SimpleEntry<org.w3c.dom.Node, Node<?>>(doc, treeRootNode));
 
         while (!jobQueue.isEmpty()) {
@@ -171,13 +180,13 @@ public abstract class NodeUtils {
     public static Map<String, ListSchemaNode> buildMapOfListNodes(final SchemaContext context) {
         Map<String, ListSchemaNode> mapOfLists = new HashMap<>();
 
-        Stack<DataSchemaNode> jobQueue = new Stack<>();
+        final Deque<DataSchemaNode> jobQueue = new ArrayDeque<>();
         jobQueue.addAll(context.getDataDefinitions());
 
         while (!jobQueue.isEmpty()) {
             DataSchemaNode dataSchema = jobQueue.pop();
             if (dataSchema instanceof ListSchemaNode) {
-                mapOfLists.put(schemaPathToPath(dataSchema.getPath().getPath()), (ListSchemaNode) dataSchema);
+                mapOfLists.put(schemaPathToPath(dataSchema.getPath().getPathFromRoot()), (ListSchemaNode) dataSchema);
             }
 
             if (dataSchema instanceof DataNodeContainer) {
@@ -192,12 +201,8 @@ public abstract class NodeUtils {
      * @param qNamesPath
      * @return path
      */
-    private static String schemaPathToPath(final List<QName> qNamesPath) {
-        List<String> pathSeed = new ArrayList<>();
-        for (QName qNameItem : qNamesPath) {
-            pathSeed.add(qNameItem.getLocalName());
-        }
-        return Joiner.on(".").join(pathSeed);
+    private static String schemaPathToPath(final Iterable<QName> qNamesPath) {
+        return DOT_JOINER.join(Iterables.transform(qNamesPath, LOCALNAME_FUNCTION));
     }
 
     /**