Merge "Improve generated toString() methods to skip null fields"
authorTony Tkacik <ttkacik@cisco.com>
Tue, 21 Jan 2014 15:24:23 +0000 (15:24 +0000)
committerGerrit Code Review <gerrit@opendaylight.org>
Tue, 21 Jan 2014 15:24:23 +0000 (15:24 +0000)
14 files changed:
code-generator/binding-generator-impl/src/main/java/org/opendaylight/yangtools/sal/binding/generator/impl/BindingGeneratorImpl.xtend
code-generator/binding-generator-impl/src/test/resources/augment-relative-xpath-models/augment-abstract-topology@2013-05-03.yang
yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/SchemaContextUtil.xtend
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/api/AbstractDataNodeContainerBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/AugmentationSchemaBuilderImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ChoiceCaseBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ContainerSchemaNodeBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/GroupingBuilderImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ListSchemaNodeBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/ModuleBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/builder/impl/NotificationBuilder.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/impl/YangParserImpl.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/Comparators.java
yang/yang-parser-impl/src/main/java/org/opendaylight/yangtools/yang/parser/util/CopyUtils.java

index 10bca49c9e9493a9d34f401c13f2fa92c95e36f6..4411c09aecbe8057a247483f66efa8f2d7230008 100644 (file)
@@ -738,8 +738,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
         checkState(augSchema.targetPath !== null,
             "Augmentation Schema does not contain Target Path (Target Path is NULL).");
 
-        processUsesAugments(augSchema, module);
-\r
+        processUsesAugments(augSchema, module);\r
         val targetPath = augSchema.targetPath;
         var targetSchemaNode = findDataSchemaNode(schemaContext, targetPath);\r
         if (targetSchemaNode instanceof DataSchemaNode && (targetSchemaNode as DataSchemaNode).isAddedByUses()) {
@@ -756,7 +755,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
         }\r
 \r
         if (targetSchemaNode == null) {\r
-            throw new IllegalArgumentException("augment target not found")\r
+            throw new IllegalArgumentException("augment target not found: " + targetPath)\r
         }\r
 
         if (targetSchemaNode !== null) {
@@ -804,10 +803,10 @@ public class BindingGeneratorImpl implements BindingGenerator {
             return null
         }
 
-        var String currentName = node.QName.localName\r
+        var QName currentName = node.QName\r
         var Object currentNode = node
         var Object parent = node;\r
-        val tmpPath = new ArrayList<String>()\r
+        val tmpPath = new ArrayList<QName>()\r
         val tmpTree = new ArrayList<SchemaNode>()\r
 
         var AugmentationSchema augment = null;
@@ -823,7 +822,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
                 tmpTree.add(currentNode as SchemaNode)\r
                 augment = findNodeInAugment((parent as AugmentationTarget).availableAugmentations, currentName);
                 if (augment == null) {
-                    currentName = (parent as DataSchemaNode).QName.localName;\r
+                    currentName = (parent as DataSchemaNode).QName\r
                     currentNode = parent
                 }
             }
@@ -838,12 +837,12 @@ public class BindingGeneratorImpl implements BindingGenerator {
             var DataSchemaNode result = null;
             for (name : tmpPath) {
                 if (actualParent instanceof DataNodeContainer) {
-                    result = (actualParent as DataNodeContainer).getDataChildByName(name);
-                    actualParent = (actualParent as DataNodeContainer).getDataChildByName(name);
+                    result = (actualParent as DataNodeContainer).getDataChildByName(name.localName);
+                    actualParent = (actualParent as DataNodeContainer).getDataChildByName(name.localName);
                 } else {
                     if (actualParent instanceof ChoiceNode) {
-                        result = (actualParent as ChoiceNode).getCaseNodeByName(name);
-                        actualParent = (actualParent as ChoiceNode).getCaseNodeByName(name);
+                        result = (actualParent as ChoiceNode).getCaseNodeByName(name.localName);
+                        actualParent = (actualParent as ChoiceNode).getCaseNodeByName(name.localName);
                     }
                 }
             }
@@ -856,9 +855,10 @@ public class BindingGeneratorImpl implements BindingGenerator {
         }
     }
 
-    private def AugmentationSchema findNodeInAugment(Collection<AugmentationSchema> augments, String name) {
-        for (augment : augments) {
-            if (augment.getDataChildByName(name) != null) {
+    private def AugmentationSchema findNodeInAugment(Collection<AugmentationSchema> augments, QName name) {
+        for (augment : augments) {\r
+            val DataSchemaNode node = augment.getDataChildByName(name);\r
+            if (node != null) {
                 return augment;
             }
         }
@@ -884,8 +884,8 @@ public class BindingGeneratorImpl implements BindingGenerator {
             return result\r
         } else {\r
             var DataSchemaNode result = null;\r
-            var String currentName = node.QName.localName\r
-            var tmpPath = new ArrayList<String>()\r
+            var QName currentName = node.QName\r
+            var tmpPath = new ArrayList<QName>()\r
             var Object parent = null\r
 
             val SchemaPath sp = node.path
@@ -900,13 +900,13 @@ public class BindingGeneratorImpl implements BindingGenerator {
                 val dataNodeParent = parent as DataNodeContainer;\r
                 for (u : dataNodeParent.uses) {\r
                     if (result == null) {\r
-                        result = getResultFromUses(u, currentName)\r
+                        result = getResultFromUses(u, currentName.localName)\r
                     }\r
                 }\r
                 if (result == null) {
-                    currentName = (parent as SchemaNode).QName.localName
-                    if (parent instanceof DataSchemaNode) {
-                        val SchemaPath nodeSp = (parent as DataSchemaNode).path
+                    currentName = (parent as SchemaNode).QName
+                    if (parent instanceof SchemaNode) {
+                        val SchemaPath nodeSp = (parent as SchemaNode).path
                         val List<QName> nodeNames = nodeSp.path
                         val List<QName> nodeNewNames = new ArrayList(nodeNames)
                         nodeNewNames.remove(nodeNewNames.size - 1)
@@ -933,8 +933,8 @@ public class BindingGeneratorImpl implements BindingGenerator {
         List<SchemaNode> dataTree) {\r
 \r
         var DataSchemaNode result = null;
-        var String currentName = node.QName.localName
-        var tmpPath = new ArrayList<String>()\r
+        var QName currentName = node.QName
+        var tmpPath = new ArrayList<QName>()\r
         tmpPath.add(currentName)\r
         var int i = 1;\r
         var Object parent = null
@@ -944,18 +944,18 @@ public class BindingGeneratorImpl implements BindingGenerator {
                 parent = parentNode
             } else {
                 parent = dataTree.get(dataTree.size - (i+1))
-                tmpPath.add((parent as SchemaNode).QName.localName);
+                tmpPath.add((parent as SchemaNode).QName)
             }\r
 
             val dataNodeParent = parent as DataNodeContainer;
             for (u : dataNodeParent.uses) {
                 if (result == null) {\r
-                    result = getResultFromUses(u, currentName)
+                    result = getResultFromUses(u, currentName.localName)
                 }
             }
             if (result == null) {
                 i = i + 1\r
-                currentName = (parent as SchemaNode).QName.localName
+                currentName = (parent as SchemaNode).QName
             }
         } while (result == null);
 \r
@@ -974,7 +974,7 @@ public class BindingGeneratorImpl implements BindingGenerator {
         return gr.getDataChildByName(currentName)
     }\r
 \r
-    private def getTargetNode(List<String> tmpPath, DataSchemaNode node) {
+    private def getTargetNode(List<QName> tmpPath, DataSchemaNode node) {
         var DataSchemaNode result = node
         if (tmpPath.size == 1) {
             if (result != null && result.addedByUses) {
@@ -986,8 +986,9 @@ public class BindingGeneratorImpl implements BindingGenerator {
             Collections.reverse(tmpPath);
 
             tmpPath.remove(0);
-            for (name : tmpPath) {
-                newParent = (newParent as DataNodeContainer).getDataChildByName(name);
+            for (name : tmpPath) {\r
+                // searching by local name is must, because node has different namespace in its original location
+                newParent = (newParent as DataNodeContainer).getDataChildByName(name.localName);
             }
             if (newParent != null && newParent.addedByUses) {
                 newParent = findOriginal(newParent);
index c9c368d536f7616042cba649259ef66d4c80e21f..fd15dce839a16e782064bddba774ea5de9c15ba9 100644 (file)
@@ -52,7 +52,7 @@ module augment-abstract-topology {
 
                 leaf tunnel-id {
                     type leafref {
-                        path "../../../link-id";
+                        path "../../../at:link-id";
                     }
                 }
             }
index de0431b5244b4a615512826ec5b5c6b07d0cc039..72d1e1891e7b1adc767c711224c629eee771530c 100644 (file)
@@ -268,7 +268,7 @@ public  class SchemaContextUtil {
             if (childNodeQName != null) {
                 schemaNode = nextNode.getDataChildByName(childNodeQName.getLocalName());
                 if(schemaNode === null && nextNode instanceof Module) {
-                    schemaNode = (nextNode as Module).getNotificationByName(childNodeQName.localName);
+                    schemaNode = (nextNode as Module).getNotificationByName(childNodeQName);
                 }
                 if(schemaNode === null && nextNode instanceof Module) {
                     
@@ -302,8 +302,8 @@ public  class SchemaContextUtil {
         }
         return schemaNode;
     }
-    
-    
+
+
     public static def SchemaNode findNodeInSchemaContext(SchemaContext context, List<QName> path) {
         val current = path.get(0);
         val module = context.findModuleByNamespaceAndRevision(current.namespace,current.revision);
@@ -339,7 +339,7 @@ public  class SchemaContextUtil {
     }
 
     private static def SchemaNode findNodeInModule(Module module, List<QName> path) {
-        val current = path.get(0).localName;
+        val current = path.get(0)
         var SchemaNode node = module.getDataChildByName(current);
         if (node != null) return findNode(node as DataSchemaNode,path.nextLevel);
         node = module.getRpcByName(current);
@@ -348,12 +348,12 @@ public  class SchemaContextUtil {
         if (node != null) return findNodeInNotification(node as NotificationDefinition,path.nextLevel)
         node = module.getGroupingByName(current);
         if (node != null) return findNodeInGrouping(node as GroupingDefinition, path.nextLevel);
-        return null
+        return node
     }
 
     private static def SchemaNode findNodeInGrouping(GroupingDefinition grouping, List<QName> path) {
         if (path.empty) return grouping;
-        val current = path.get(0).localName;
+        val current = path.get(0)
         val node = grouping.getDataChildByName(current);
         if (node != null) return findNode(node, path.nextLevel);
         return null;
@@ -371,7 +371,7 @@ public  class SchemaContextUtil {
     
     private static def SchemaNode findNodeInNotification(NotificationDefinition rpc,List<QName> path) {
         if(path.empty) return rpc;
-        val current = path.get(0).localName;
+        val current = path.get(0)
         val node = rpc.getDataChildByName(current)
         if(node != null) return findNode(node,path.nextLevel)
         return null
@@ -379,7 +379,7 @@ public  class SchemaContextUtil {
     
     private static dispatch def SchemaNode findNode(ChoiceNode parent,List<QName> path) {
         if(path.empty) return parent;
-        val current = path.get(0).localName;
+        val current = path.get(0)
         val node = parent.getCaseNodeByName(current)
         if (node != null) return findNodeInCase(node,path.nextLevel)
         return null
@@ -387,7 +387,7 @@ public  class SchemaContextUtil {
     
     private static dispatch def SchemaNode findNode(ContainerSchemaNode parent,List<QName> path) {
         if(path.empty) return parent;
-         val current = path.get(0).localName;
+         val current = path.get(0)
         val node = parent.getDataChildByName(current)
         if (node != null) return findNode(node,path.nextLevel)
         return null
@@ -395,7 +395,7 @@ public  class SchemaContextUtil {
     
     private static dispatch def SchemaNode findNode(ListSchemaNode parent,List<QName> path) {
         if(path.empty) return parent;
-         val current = path.get(0).localName;
+         val current = path.get(0)
         val node = parent.getDataChildByName(current)
         if (node != null) return findNode(node,path.nextLevel)
         return null
@@ -411,17 +411,17 @@ public  class SchemaContextUtil {
     
     public static  def SchemaNode findNodeInCase(ChoiceCaseNode parent,List<QName> path) {
         if(path.empty) return parent;
-         val current = path.get(0).localName;
+         val current = path.get(0)
         val node = parent.getDataChildByName(current)
         if (node != null) return findNode(node,path.nextLevel)
         return null
     }
     
      
-    public static def RpcDefinition getRpcByName(Module module, String name) {
-        for(notification : module.rpcs) {
-            if(notification.QName.localName == name) {
-                return notification;
+    public static def RpcDefinition getRpcByName(Module module, QName name) {
+        for (rpc : module.rpcs) {
+            if (rpc.QName.equals(name)) {
+                return rpc;
             }
         }
         return null;
@@ -432,18 +432,18 @@ public  class SchemaContextUtil {
         return path.subList(1,path.size)
     }
     
-    public static def NotificationDefinition getNotificationByName(Module module, String name) {
+    public static def NotificationDefinition getNotificationByName(Module module, QName name) {
         for(notification : module.notifications) {
-            if(notification.QName.localName == name) {
+            if(notification.QName.equals(name)) {
                 return notification;
             }
         }
         return null;
     }
     
-    public static def GroupingDefinition getGroupingByName(Module module, String name) {
+    public static def GroupingDefinition getGroupingByName(Module module, QName name) {
         for (grouping : module.groupings) {
-            if (grouping.QName.localName.equals(name)) {
+            if (grouping.QName.equals(name)) {
                 return grouping;
             }
         }
@@ -617,9 +617,8 @@ public  class SchemaContextUtil {
                 if (path != null) {
                     val int lenght = path.size() - colCount;
                     absolutePath.addAll(path.subList(0,lenght));
-                    absolutePath.addAll(
-                        xpaths.subList(colCount,xpaths.length).map[stringPathPartToQName(context, module,it)]
-                    )
+                    val List<QName> sublist = xpaths.subList(colCount,xpaths.length).map[stringPathPartToQName(context, module,it)]
+                    absolutePath.addAll(sublist)
                 }
             }
         }
index 39c4c5e78af6883458f551327048b4c4f1b400af..798862b457df19dacefad5cca4a00a2571820dc6 100644 (file)
@@ -9,9 +9,7 @@ package org.opendaylight.yangtools.yang.parser.builder.api;
 
 import java.util.Collections;
 import java.util.HashSet;
-import java.util.Map;
 import java.util.Set;
-import java.util.TreeMap;
 import java.util.TreeSet;
 
 import org.opendaylight.yangtools.yang.common.QName;
@@ -28,7 +26,7 @@ import org.opendaylight.yangtools.yang.parser.util.YangParseException;
 public abstract class AbstractDataNodeContainerBuilder extends AbstractBuilder implements DataNodeContainerBuilder {
     protected QName qname;
 
-    protected final Map<QName, DataSchemaNode> childNodes = new TreeMap<>(Comparators.QNAME_COMP);
+    protected final Set<DataSchemaNode> childNodes = new HashSet<>();
     protected final Set<DataSchemaNodeBuilder> addedChildNodes = new HashSet<>();
 
     protected final Set<GroupingDefinition> groupings = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
@@ -50,7 +48,7 @@ public abstract class AbstractDataNodeContainerBuilder extends AbstractBuilder i
         return qname;
     }
 
-    public Map<QName, DataSchemaNode> getChildNodes() {
+    public Set<DataSchemaNode> getChildNodes() {
         return childNodes;
     }
 
@@ -90,13 +88,13 @@ public abstract class AbstractDataNodeContainerBuilder extends AbstractBuilder i
     @Override
     public void addChildNode(DataSchemaNode child) {
         QName childName = child.getQName();
-        for (QName qname : childNodes.keySet()) {
-            if (qname.equals(childName)) {
+        for (DataSchemaNode childNode : childNodes) {
+            if (childNode.getQName().equals(childName)) {
                 throw new YangParseException(moduleName, line, "Can not add '" + child + "' to '" + this
                         + "' in module '" + moduleName + "': node with same name already declared");
             }
         }
-        childNodes.put(child.getQName(), child);
+        childNodes.add(child);
     }
 
     @Override
@@ -143,4 +141,22 @@ public abstract class AbstractDataNodeContainerBuilder extends AbstractBuilder i
         addedUsesNodes.add(usesNode);
     }
 
+    public DataSchemaNode getChildNode(Set<DataSchemaNode> childNodes, QName name) {
+        for (DataSchemaNode node : childNodes) {
+            if (node.getQName().equals(name)) {
+                return node;
+            }
+        }
+        return null;
+    }
+
+    public DataSchemaNode getChildNode(Set<DataSchemaNode> childNodes, String name) {
+        for (DataSchemaNode node : childNodes) {
+            if (node.getQName().getLocalName().equals(name)) {
+                return node;
+            }
+        }
+        return null;
+    }
+
 }
index 0ef1e4eba962bf6bb3f79f425496239a8b679ba8..cdf0fe571865c778e2ea3eddafb87602974ca507 100644 (file)
@@ -9,10 +9,8 @@ package org.opendaylight.yangtools.yang.parser.builder.impl;
 
 import java.util.ArrayList;
 import java.util.Collections;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 
@@ -93,7 +91,7 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
             // CHILD NODES
             for (DataSchemaNodeBuilder node : addedChildNodes) {
                 DataSchemaNode child = node.build();
-                childNodes.put(child.getQName(), child);
+                childNodes.add(child);
             }
             instance.addChildNodes(childNodes);
 
@@ -248,7 +246,7 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
     private final class AugmentationSchemaImpl implements AugmentationSchema {
         private SchemaPath targetPath;
         private RevisionAwareXPath whenCondition;
-        private final Map<QName, DataSchemaNode> childNodes = new HashMap<>();
+        private final Set<DataSchemaNode> childNodes = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         private final Set<UsesNode> uses = new HashSet<>();
         private String description;
         private String reference;
@@ -279,14 +277,12 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
 
         @Override
         public Set<DataSchemaNode> getChildNodes() {
-            final Set<DataSchemaNode> result = new TreeSet<DataSchemaNode>(Comparators.SCHEMA_NODE_COMP);
-            result.addAll(childNodes.values());
-            return Collections.unmodifiableSet(result);
+            return Collections.unmodifiableSet(childNodes);
         }
 
-        private void addChildNodes(Map<QName, DataSchemaNode> childNodes) {
+        private void addChildNodes(Set<DataSchemaNode> childNodes) {
             if (childNodes != null) {
-                this.childNodes.putAll(childNodes);
+                this.childNodes.addAll(childNodes);
             }
         }
 
@@ -347,19 +343,12 @@ public final class AugmentationSchemaBuilderImpl extends AbstractDataNodeContain
 
         @Override
         public DataSchemaNode getDataChildByName(QName name) {
-            return childNodes.get(name);
+            return getChildNode(childNodes, name);
         }
 
         @Override
         public DataSchemaNode getDataChildByName(String name) {
-            DataSchemaNode result = null;
-            for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
-                if (entry.getKey().getLocalName().equals(name)) {
-                    result = entry.getValue();
-                    break;
-                }
-            }
-            return result;
+            return getChildNode(childNodes, name);
         }
 
         @Override
index 983828ec1b1817e4aec5e7d98c8975019507ae8b..b8fd424805a8ff51ee683c5f57fa3c8cb60a9ae7 100644 (file)
@@ -11,11 +11,10 @@ import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
+import java.util.TreeSet;
 
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.*;
@@ -78,8 +77,7 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
 
             // CHILD NODES
             for (DataSchemaNodeBuilder node : addedChildNodes) {
-                DataSchemaNode child = node.build();
-                childNodes.put(child.getQName(), child);
+                childNodes.add(node.build());
             }
             instance.addChildNodes(childNodes);
 
@@ -249,7 +247,7 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
         private boolean augmenting;
         private boolean addedByUses;
         private ConstraintDefinition constraints;
-        private final Map<QName, DataSchemaNode> childNodes = new HashMap<>();
+        private final Set<DataSchemaNode> childNodes = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         private final Set<AugmentationSchema> augmentations = new HashSet<>();
         private final Set<UsesNode> uses = new HashSet<>();
         private final List<UnknownSchemaNode> unknownNodes = new ArrayList<>();
@@ -330,12 +328,12 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
 
         @Override
         public Set<DataSchemaNode> getChildNodes() {
-            return Collections.unmodifiableSet(new HashSet<>(childNodes.values()));
+            return Collections.unmodifiableSet(childNodes);
         }
 
-        private void addChildNodes(Map<QName, DataSchemaNode> childNodes) {
+        private void addChildNodes(Set<DataSchemaNode> childNodes) {
             if (childNodes != null) {
-                this.childNodes.putAll(childNodes);
+                this.childNodes.addAll(childNodes);
             }
         }
 
@@ -346,19 +344,12 @@ public final class ChoiceCaseBuilder extends AbstractDataNodeContainerBuilder im
 
         @Override
         public DataSchemaNode getDataChildByName(QName name) {
-            return childNodes.get(name);
+            return getChildNode(childNodes, name);
         }
 
         @Override
         public DataSchemaNode getDataChildByName(String name) {
-            DataSchemaNode result = null;
-            for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
-                if (entry.getKey().getLocalName().equals(name)) {
-                    result = entry.getValue();
-                    break;
-                }
-            }
-            return result;
+            return getChildNode(childNodes, name);
         }
 
         @Override
index 4156ba3a062b538a7739d28e5afe34675b445ba4..94c6cb19a5e558f3876d1bb5c5e32d0e9893c6c5 100644 (file)
@@ -11,10 +11,8 @@ import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 
@@ -102,8 +100,7 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
 
             // CHILD NODES
             for (DataSchemaNodeBuilder node : addedChildNodes) {
-                DataSchemaNode child = node.build();
-                childNodes.put(child.getQName(), child);
+                childNodes.add(node.build());
             }
             instance.addChildNodes(childNodes);
 
@@ -306,7 +303,7 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
         private boolean configuration;
         private ConstraintDefinition constraints;
         private final Set<AugmentationSchema> augmentations = new HashSet<>();
-        private final Map<QName, DataSchemaNode> childNodes = new HashMap<>();
+        private final Set<DataSchemaNode> childNodes = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         private final Set<GroupingDefinition> groupings = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         private final Set<TypeDefinition<?>> typeDefinitions = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         private final Set<UsesNode> uses = new HashSet<>();
@@ -384,14 +381,12 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
 
         @Override
         public Set<DataSchemaNode> getChildNodes() {
-            final Set<DataSchemaNode> result = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
-            result.addAll(childNodes.values());
-            return Collections.unmodifiableSet(result);
+            return Collections.unmodifiableSet(childNodes);
         }
 
-        private void addChildNodes(Map<QName, DataSchemaNode> childNodes) {
+        private void addChildNodes(Set<DataSchemaNode> childNodes) {
             if (childNodes != null) {
-                this.childNodes.putAll(childNodes);
+                this.childNodes.addAll(childNodes);
             }
         }
 
@@ -408,19 +403,12 @@ public final class ContainerSchemaNodeBuilder extends AbstractDataNodeContainerB
 
         @Override
         public DataSchemaNode getDataChildByName(QName name) {
-            return childNodes.get(name);
+            return getChildNode(childNodes, name);
         }
 
         @Override
         public DataSchemaNode getDataChildByName(String name) {
-            DataSchemaNode result = null;
-            for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
-                if (entry.getKey().getLocalName().equals(name)) {
-                    result = entry.getValue();
-                    break;
-                }
-            }
-            return result;
+            return getChildNode(childNodes, name);
         }
 
         @Override
index e8ff3040eb082354710b665ea6000c1778326813..ee155ba1c32e0d2d1e2282981e39179c465bb7ac 100644 (file)
@@ -11,10 +11,8 @@ import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 
@@ -75,8 +73,7 @@ public final class GroupingBuilderImpl extends AbstractDataNodeContainerBuilder
         if (!isBuilt) {
             // CHILD NODES
             for (DataSchemaNodeBuilder node : addedChildNodes) {
-                DataSchemaNode child = node.build();
-                childNodes.put(child.getQName(), child);
+                childNodes.add(node.build());
             }
             instance.addChildNodes(childNodes);
 
@@ -273,7 +270,7 @@ public final class GroupingBuilderImpl extends AbstractDataNodeContainerBuilder
         private String reference;
         private Status status;
         private boolean addedByUses;
-        private final Map<QName, DataSchemaNode> childNodes = new HashMap<>();
+        private final Set<DataSchemaNode> childNodes = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         private final Set<GroupingDefinition> groupings = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         private final Set<TypeDefinition<?>> typeDefinitions = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         private final Set<UsesNode> uses = new HashSet<>();
@@ -316,16 +313,13 @@ public final class GroupingBuilderImpl extends AbstractDataNodeContainerBuilder
 
         @Override
         public Set<DataSchemaNode> getChildNodes() {
-            final Set<DataSchemaNode> result = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
-            result.addAll(childNodes.values());
-            return Collections.unmodifiableSet(result);
+            return Collections.unmodifiableSet(childNodes);
         }
 
-        private void addChildNodes(Map<QName, DataSchemaNode> childNodes) {
+        private void addChildNodes(Set<DataSchemaNode> childNodes) {
             if (childNodes != null) {
-                this.childNodes.putAll(childNodes);
+                this.childNodes.addAll(childNodes);
             }
-
         }
 
         @Override
@@ -374,19 +368,12 @@ public final class GroupingBuilderImpl extends AbstractDataNodeContainerBuilder
 
         @Override
         public DataSchemaNode getDataChildByName(QName name) {
-            return childNodes.get(name);
+            return getChildNode(childNodes, name);
         }
 
         @Override
         public DataSchemaNode getDataChildByName(String name) {
-            DataSchemaNode result = null;
-            for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
-                if (entry.getKey().getLocalName().equals(name)) {
-                    result = entry.getValue();
-                    break;
-                }
-            }
-            return result;
+            return getChildNode(childNodes, name);
         }
 
         @Override
index ac737fb2ca4111cbe85574a83f1094a2d2b3b21c..e3bea979b456c964bc3271786f8935ed97679818 100644 (file)
@@ -11,10 +11,8 @@ import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
 import java.util.TreeSet;
 
@@ -86,8 +84,7 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
         if (!isBuilt) {
             // CHILD NODES
             for (DataSchemaNodeBuilder node : addedChildNodes) {
-                DataSchemaNode child = node.build();
-                childNodes.put(child.getQName(), child);
+                childNodes.add(node.build());
             }
             instance.addChildNodes(childNodes);
 
@@ -302,7 +299,7 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
         private boolean configuration;
         private ConstraintDefinition constraints;
         private final Set<AugmentationSchema> augmentations = new HashSet<>();
-        private final Map<QName, DataSchemaNode> childNodes = new HashMap<>();
+        private final Set<DataSchemaNode> childNodes = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         private final Set<TypeDefinition<?>> typeDefinitions = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         private final Set<GroupingDefinition> groupings = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         private final Set<UsesNode> uses = new HashSet<>();
@@ -381,14 +378,12 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
 
         @Override
         public Set<DataSchemaNode> getChildNodes() {
-            final Set<DataSchemaNode> result = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
-            result.addAll(childNodes.values());
-            return Collections.unmodifiableSet(result);
+            return Collections.unmodifiableSet(childNodes);
         }
 
-        private void addChildNodes(Map<QName, DataSchemaNode> childNodes) {
+        private void addChildNodes(Set<DataSchemaNode> childNodes) {
             if (childNodes != null) {
-                this.childNodes.putAll(childNodes);
+                this.childNodes.addAll(childNodes);
             }
         }
 
@@ -427,19 +422,12 @@ public final class ListSchemaNodeBuilder extends AbstractDataNodeContainerBuilde
 
         @Override
         public DataSchemaNode getDataChildByName(QName name) {
-            return childNodes.get(name);
+            return getChildNode(childNodes, name);
         }
 
         @Override
         public DataSchemaNode getDataChildByName(String name) {
-            DataSchemaNode result = null;
-            for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
-                if (entry.getKey().getLocalName().equals(name)) {
-                    result = entry.getValue();
-                    break;
-                }
-            }
-            return result;
+            return getChildNode(childNodes, name);
         }
 
         @Override
index 15969e6677821ad4deb00362787b594a454e148e..36ff7bfe6afae2ee856145a11f892b2d8e8f6764 100644 (file)
@@ -103,7 +103,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         revision = base.getRevision();
 
         for (DataSchemaNode childNode : base.getChildNodes()) {
-            childNodes.put(childNode.getQName(), childNode);
+            childNodes.add(childNode);
         }
 
         typedefs.addAll(base.getTypeDefinitions());
@@ -137,8 +137,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
 
         // CHILD NODES
         for (DataSchemaNodeBuilder child : addedChildNodes) {
-            DataSchemaNode childNode = child.build();
-            childNodes.put(childNode.getQName(), childNode);
+            childNodes.add(child.build());
         }
         instance.addChildNodes(childNodes);
 
@@ -890,7 +889,7 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
         private final Set<AugmentationSchema> augmentations = new HashSet<>();
         private final Set<RpcDefinition> rpcs = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         private final Set<Deviation> deviations = new HashSet<>();
-        private final Map<QName, DataSchemaNode> childNodes = new TreeMap<>(Comparators.QNAME_COMP);
+        private final Set<DataSchemaNode> childNodes = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         private final Set<GroupingDefinition> groupings = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         private final Set<UsesNode> uses = new HashSet<>();
         private final List<ExtensionDefinition> extensionNodes = new ArrayList<>();
@@ -1057,14 +1056,12 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
 
         @Override
         public Set<DataSchemaNode> getChildNodes() {
-            final Set<DataSchemaNode> result = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
-            result.addAll(childNodes.values());
-            return Collections.unmodifiableSet(result);
+            return Collections.unmodifiableSet(childNodes);
         }
 
-        private void addChildNodes(Map<QName, DataSchemaNode> childNodes) {
+        private void addChildNodes(Set<DataSchemaNode> childNodes) {
             if (childNodes != null) {
-                this.childNodes.putAll(childNodes);
+                this.childNodes.addAll(childNodes);
             }
         }
 
@@ -1126,19 +1123,12 @@ public class ModuleBuilder extends AbstractDataNodeContainerBuilder {
 
         @Override
         public DataSchemaNode getDataChildByName(QName name) {
-            return childNodes.get(name);
+            return getChildNode(childNodes, name);
         }
 
         @Override
         public DataSchemaNode getDataChildByName(String name) {
-            DataSchemaNode result = null;
-            for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
-                if (entry.getKey().getLocalName().equals(name)) {
-                    result = entry.getValue();
-                    break;
-                }
-            }
-            return result;
+            return getChildNode(childNodes, name);
         }
 
         @Override
index 7e96ba30cd8932ab4c95e9f645a459878f11a8f9..21c29568500e60ff6f7577425a3dc2eccc2e511c 100644 (file)
@@ -11,11 +11,10 @@ import java.net.URI;
 import java.util.ArrayList;
 import java.util.Collections;
 import java.util.Date;
-import java.util.HashMap;
 import java.util.HashSet;
 import java.util.List;
-import java.util.Map;
 import java.util.Set;
+import java.util.TreeSet;
 
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.AugmentationSchema;
@@ -83,8 +82,7 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
         if (!isBuilt) {
             // CHILD NODES
             for (DataSchemaNodeBuilder node : addedChildNodes) {
-                DataSchemaNode child = node.build();
-                childNodes.put(child.getQName(), child);
+                childNodes.add(node.build());
             }
             instance.setChildNodes(childNodes);
 
@@ -189,7 +187,7 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
         private String description;
         private String reference;
         private Status status = Status.CURRENT;
-        private final Map<QName, DataSchemaNode> childNodes = new HashMap<>();
+        private final Set<DataSchemaNode> childNodes = new TreeSet<>(Comparators.SCHEMA_NODE_COMP);
         private final Set<GroupingDefinition> groupings = new HashSet<>();
         private final Set<TypeDefinition<?>> typeDefinitions = new HashSet<>();
         private final Set<UsesNode> uses = new HashSet<>();
@@ -228,12 +226,12 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
 
         @Override
         public Set<DataSchemaNode> getChildNodes() {
-            return Collections.unmodifiableSet(new HashSet<DataSchemaNode>(childNodes.values()));
+            return Collections.unmodifiableSet(childNodes);
         }
 
-        private void setChildNodes(Map<QName, DataSchemaNode> childNodes) {
+        private void setChildNodes(Set<DataSchemaNode> childNodes) {
             if (childNodes != null) {
-                this.childNodes.putAll(childNodes);
+                this.childNodes.addAll(childNodes);
             }
         }
 
@@ -294,19 +292,12 @@ public final class NotificationBuilder extends AbstractDataNodeContainerBuilder
 
         @Override
         public DataSchemaNode getDataChildByName(QName name) {
-            return childNodes.get(name);
+            return getChildNode(childNodes, name);
         }
 
         @Override
         public DataSchemaNode getDataChildByName(String name) {
-            DataSchemaNode result = null;
-            for (Map.Entry<QName, DataSchemaNode> entry : childNodes.entrySet()) {
-                if (entry.getKey().getLocalName().equals(name)) {
-                    result = entry.getValue();
-                    break;
-                }
-            }
-            return result;
+            return getChildNode(childNodes, name);
         }
 
         @Override
index 9b3a0a40305397e7070a936028d8f1bcff5d9643..73291d16ec06e40c8bbfa313eb7be358e93c6bd4 100644 (file)
@@ -334,7 +334,7 @@ public final class YangParserImpl implements YangModelParser {
         module.getAugmentBuilders().addAll(submodule.getAugmentBuilders());
         module.getAllAugments().addAll(submodule.getAllAugments());
         module.getChildNodeBuilders().addAll(submodule.getChildNodeBuilders());
-        module.getChildNodes().putAll(submodule.getChildNodes());
+        module.getChildNodes().addAll(submodule.getChildNodes());
         module.getGroupings().addAll(submodule.getGroupings());
         module.getGroupingBuilders().addAll(submodule.getGroupingBuilders());
         module.getTypeDefinitions().addAll(submodule.getTypeDefinitions());
@@ -465,7 +465,7 @@ public final class YangParserImpl implements YangModelParser {
         }
         return result;
     }
-    
+
     public static YangContext parseStreamWithoutErrorListeners(final InputStream yangStream) {
         YangContext result = null;
         try {
index 816db28e34c47e44073be7a908136cdb431849fe..ed33bac1e9b631928c73b8e91f0e2bdee6597ebf 100644 (file)
@@ -7,7 +7,9 @@
  */
 package org.opendaylight.yangtools.yang.parser.util;
 
+import java.net.URI;
 import java.util.Comparator;
+import java.util.Date;
 
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.model.api.SchemaNode;
@@ -43,7 +45,51 @@ public final class Comparators {
     private static final class SchemaNodeComparator implements Comparator<SchemaNode> {
         @Override
         public int compare(SchemaNode o1, SchemaNode o2) {
-            return o1.getQName().getLocalName().compareTo(o2.getQName().getLocalName());
+            QName q1 = o1.getQName();
+            QName q2 = o2.getQName();
+            int result = q1.getLocalName().compareTo(q2.getLocalName());
+            if (result == 0) {
+                URI ns1 = q1.getNamespace();
+                URI ns2 = q2.getNamespace();
+                if (ns1 == null && ns2 == null) {
+                    Date rev1 = q1.getRevision();
+                    Date rev2 = q2.getRevision();
+
+                    if (rev1 == null && rev2 == null) {
+                        String p1 = q1.getPrefix();
+                        String p2 = q2.getPrefix();
+                        if (p1 == null && p2 == null) {
+                            throw new IllegalArgumentException("Failed to sort nodes: " + o1 + ", " + o2);
+                        }
+                        if (p1 == null || p2 == null) {
+                            if (p1 == null) {
+                                return -1;
+                            } else {
+                                return 1;
+                            }
+                        }
+                        return p1.compareTo(p2);
+                    }
+                    if (rev1 == null || rev2 == null) {
+                        if (rev1 == null) {
+                            return -1;
+                        } else {
+                            return -2;
+                        }
+                    }
+                    return rev1.compareTo(rev2);
+                }
+                if (ns1 == null || ns2 == null) {
+                    if (ns1 == null) {
+                        return -1;
+                    } else {
+                        return 1;
+                    }
+                }
+                return ns1.toString().compareTo(ns2.toString());
+            } else {
+                return result;
+            }
         }
     }
 
index 3cee12eb103ad01ce82c15a32070dc7e9be9df86..05e1e0c1942ec7889ece972edb1966a916bff1c3 100644 (file)
@@ -418,6 +418,8 @@ public final class CopyUtils {
         UnknownSchemaNodeBuilder c = new UnknownSchemaNodeBuilder(newParent.getModuleName(), newParent.getLine(),
                 newQName, newSchemaPath);
 
+        c.setNodeType(old.getNodeType());
+        c.setNodeParameter(old.getNodeParameter());
         c.setParent(newParent);
         c.setDescription(old.getDescription());
         c.setReference(old.getReference());