Merge "BUG-648: add missing copy builders"
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / NodeUtils.java
index 6473c8100a15f7f615eb314e9df2bd31812c8789..56c814bfde79844310d11fa7b278d00be54a1029 100644 (file)
@@ -23,6 +23,7 @@ import javax.xml.xpath.XPathExpression;
 import javax.xml.xpath.XPathExpressionException;
 import javax.xml.xpath.XPathFactory;
 
+import com.google.common.collect.Maps;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.CompositeNode;
 import org.opendaylight.yangtools.yang.data.api.ModifyAction;
@@ -42,7 +43,7 @@ import com.google.common.collect.Lists;
 
 /**
  * @author michal.rehak
- * 
+ *
  */
 public abstract class NodeUtils {
 
@@ -96,7 +97,9 @@ public abstract class NodeUtils {
             itemEl.setUserData(USER_KEY_NODE, item, null);
             if (item instanceof SimpleNode<?>) {
                 Object value = ((SimpleNode<?>) item).getValue();
-                itemEl.setTextContent(String.valueOf(value));
+                if(value != null) {
+                    itemEl.setTextContent(String.valueOf(value));
+                }
             }
             if (item instanceof NodeModification) {
                 ModifyAction modificationAction = ((NodeModification) item).getModificationAction();
@@ -140,14 +143,14 @@ public abstract class NodeUtils {
 
     /**
      * build NodeMap, where key = qName; value = node
-     * 
+     *
      * @param value
      * @return map of children, where key = qName and value is list of children
      *         groupped by qName
      */
     public static Map<QName, List<Node<?>>> buildNodeMap(List<Node<?>> value) {
-        Map<QName, List<Node<?>>> nodeMapTmp = new HashMap<>();
-        if (value == null || value.isEmpty()) {
+        Map<QName, List<Node<?>>> nodeMapTmp = Maps.newLinkedHashMap();
+        if (value == null) {
             throw new IllegalStateException("nodeList should not be null or empty");
         }
         for (Node<?> node : value) {
@@ -186,8 +189,8 @@ public abstract class NodeUtils {
     }
 
     /**
-     * @param path
-     * @return
+     * @param qNamesPath
+     * @return path
      */
     private static String schemaPathToPath(List<QName> qNamesPath) {
         List<String> pathSeed = new ArrayList<>();
@@ -199,7 +202,7 @@ public abstract class NodeUtils {
 
     /**
      * add given node to it's parent's list of children
-     * 
+     *
      * @param newNode
      */
     public static void fixParentRelation(Node<?> newNode) {
@@ -213,7 +216,7 @@ public abstract class NodeUtils {
 
     /**
      * crawl all children of given node and assign it as their parent
-     * 
+     *
      * @param parentNode
      */
     public static void fixChildrenRelation(CompositeNode parentNode) {