Remove an unneeded warning suppression
[yangtools.git] / yang / yang-data-impl / src / main / java / org / opendaylight / yangtools / yang / data / impl / schema / SchemaOrderedNormalizedNodeWriter.java
index fa28b02717487d27fc6cf72098472ab47bccbe97..5a364ee6b8910f4ba356e4c8210671f96de881c0 100644 (file)
@@ -11,9 +11,9 @@ import static com.google.common.base.Preconditions.checkArgument;
 import static java.util.Objects.requireNonNull;
 
 import com.google.common.collect.ArrayListMultimap;
+import com.google.common.collect.Multimap;
 import java.io.IOException;
 import java.util.Collection;
-import java.util.List;
 import org.opendaylight.yangtools.yang.common.QName;
 import org.opendaylight.yangtools.yang.data.api.schema.AugmentationNode;
 import org.opendaylight.yangtools.yang.data.api.schema.DataContainerChild;
@@ -79,7 +79,7 @@ public class SchemaOrderedNormalizedNodeWriter extends NormalizedNodeWriter {
     @Override
     public SchemaOrderedNormalizedNodeWriter write(final NormalizedNode node) throws IOException {
         if (schemaContext.equals(root)) {
-            currentSchemaNode = schemaContext.dataChildByName(node.getNodeType());
+            currentSchemaNode = schemaContext.dataChildByName(node.getIdentifier().getNodeType());
         } else {
             currentSchemaNode = root;
         }
@@ -124,7 +124,7 @@ public class SchemaOrderedNormalizedNodeWriter extends NormalizedNodeWriter {
         throw new IllegalStateException("It wasn't possible to serialize node " + node);
     }
 
-    private void write(final List<NormalizedNode> nodes, final SchemaNode dataSchemaNode) throws IOException {
+    private void write(final Collection<NormalizedNode> nodes, final SchemaNode dataSchemaNode) throws IOException {
         for (final NormalizedNode node : nodes) {
             write(node, dataSchemaNode);
         }
@@ -137,29 +137,25 @@ public class SchemaOrderedNormalizedNodeWriter extends NormalizedNodeWriter {
 
     private boolean writeChildren(final Iterable<? extends NormalizedNode> children, final SchemaNode parentSchemaNode,
             final boolean endParent) throws IOException {
-        //Augmentations cannot be gotten with node.getChild so create our own structure with augmentations resolved
-        final ArrayListMultimap<QName, NormalizedNode> qNameToNodes = ArrayListMultimap.create();
+        // Augmentations cannot be gotten with node.getChild so create our own structure with augmentations resolved
+        final Multimap<QName, NormalizedNode> qnameToNodes = ArrayListMultimap.create();
         for (final NormalizedNode child : children) {
-            if (child instanceof AugmentationNode) {
-                qNameToNodes.putAll(resolveAugmentations(child));
-            } else {
-                qNameToNodes.put(child.getNodeType(), child);
-            }
+            putChild(qnameToNodes, child);
         }
 
         if (parentSchemaNode instanceof DataNodeContainer) {
-            if (parentSchemaNode instanceof ListSchemaNode && qNameToNodes.containsKey(parentSchemaNode.getQName())) {
-                write(qNameToNodes.get(parentSchemaNode.getQName()), parentSchemaNode);
+            if (parentSchemaNode instanceof ListSchemaNode && qnameToNodes.containsKey(parentSchemaNode.getQName())) {
+                write(qnameToNodes.get(parentSchemaNode.getQName()), parentSchemaNode);
             } else {
                 for (final DataSchemaNode schemaNode : ((DataNodeContainer) parentSchemaNode).getChildNodes()) {
-                    write(qNameToNodes.get(schemaNode.getQName()), schemaNode);
+                    write(qnameToNodes.get(schemaNode.getQName()), schemaNode);
                 }
             }
         } else if (parentSchemaNode instanceof ChoiceSchemaNode) {
             for (final CaseSchemaNode ccNode : ((ChoiceSchemaNode) parentSchemaNode).getCases()) {
                 for (final DataSchemaNode dsn : ccNode.getChildNodes()) {
-                    if (qNameToNodes.containsKey(dsn.getQName())) {
-                        write(qNameToNodes.get(dsn.getQName()), dsn);
+                    if (qnameToNodes.containsKey(dsn.getQName())) {
+                        write(qnameToNodes.get(dsn.getQName()), dsn);
                     }
                 }
             }
@@ -182,16 +178,14 @@ public class SchemaOrderedNormalizedNodeWriter extends NormalizedNodeWriter {
         throw new IllegalStateException("It wasn't possible to serialize node " + node);
     }
 
-    private ArrayListMultimap<QName, NormalizedNode> resolveAugmentations(final NormalizedNode child) {
-        final ArrayListMultimap<QName, NormalizedNode> resolvedAugs = ArrayListMultimap.create();
-        for (final NormalizedNode node : ((AugmentationNode) child).body()) {
-            if (node instanceof AugmentationNode) {
-                resolvedAugs.putAll(resolveAugmentations(node));
-            } else {
-                resolvedAugs.put(node.getNodeType(), node);
+    private static void putChild(final Multimap<QName, NormalizedNode> qnameToNodes, final NormalizedNode child) {
+        if (child instanceof AugmentationNode) {
+            for (DataContainerChild grandChild : ((AugmentationNode) child).body()) {
+                putChild(qnameToNodes, grandChild);
             }
+        } else {
+            qnameToNodes.put(child.getIdentifier().getNodeType(), child);
         }
-        return resolvedAugs;
     }
 
     private final class SchemaNodeSetter implements AutoCloseable {