Fixing sonar issues 4
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / DataNodeIterator.java
index 24e7f221e0d9eebd963e6afcaf58b073aad79da5..6fb90d96cb3b1e60160447102706171105922b1f 100644 (file)
-/*\r
- * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.\r
- *\r
- * This program and the accompanying materials are made available under the\r
- * terms of the Eclipse Public License v1.0 which accompanies this distribution,\r
- * and is available at http://www.eclipse.org/legal/epl-v10.html\r
- */\r
-package org.opendaylight.yangtools.yang.model.util;\r
-\r
-import java.util.ArrayList;\r
-import java.util.Iterator;\r
-import java.util.List;\r
-import java.util.Set;\r
-\r
-import org.opendaylight.yangtools.yang.model.api.*;\r
-\r
-public class DataNodeIterator implements Iterator<DataSchemaNode> {\r
-\r
-    private final DataNodeContainer container;\r
-    private final List<ListSchemaNode> allLists;\r
-    private final List<ContainerSchemaNode> allContainers;\r
-    private final List<ChoiceNode> allChoices;\r
-    private final List<DataSchemaNode> allChilds;\r
-    \r
-    public DataNodeIterator(final DataNodeContainer container) {\r
-        if (container == null) {\r
-            throw new IllegalArgumentException("Data Node Container MUST be specified and cannot be NULL!");\r
-        }\r
-\r
-        this.allContainers = new ArrayList<>();\r
-        this.allLists = new ArrayList<>();\r
-        this.allChilds = new ArrayList<>();\r
-        this.allChoices = new ArrayList<>();\r
-\r
-        this.container = container;\r
-        traverse(this.container);\r
-    }\r
-\r
-    public List<ContainerSchemaNode> allContainers() {\r
-        return allContainers;\r
-    }\r
-\r
-    public List<ListSchemaNode> allLists() {\r
-        return allLists;\r
-    }\r
-\r
-    public List<ChoiceNode> allChoices() {\r
-        return allChoices;\r
-    }\r
-\r
-    private void traverse(final DataNodeContainer dataNode) {\r
-        if (dataNode == null) {\r
-            return;\r
-        }\r
-\r
-        final Set<DataSchemaNode> childNodes = dataNode.getChildNodes();\r
-        if (childNodes != null) {\r
-            for (DataSchemaNode childNode : childNodes) {\r
-                if (childNode.isAugmenting()) {\r
-                    continue;\r
-                }\r
-                allChilds.add(childNode);\r
-                if (childNode instanceof ContainerSchemaNode) {\r
-                    final ContainerSchemaNode container = (ContainerSchemaNode) childNode;\r
-                    allContainers.add(container);\r
-                    traverse(container);\r
-                } else if (childNode instanceof ListSchemaNode) {\r
-                    final ListSchemaNode list = (ListSchemaNode) childNode;\r
-                    allLists.add(list);\r
-                    traverse(list);\r
-                } else if (childNode instanceof ChoiceNode) {\r
-                    final ChoiceNode choiceNode = (ChoiceNode) childNode;\r
-                    allChoices.add(choiceNode);\r
-                    final Set<ChoiceCaseNode> cases = choiceNode.getCases();\r
-                    if (cases != null) {\r
-                        for (final ChoiceCaseNode caseNode : cases) {\r
-                            traverse(caseNode);\r
-                        }\r
-                    }\r
-                }\r
-            }\r
-        }\r
-\r
-        if(dataNode instanceof Module) {\r
-            traverseModule((Module)dataNode);\r
-        }\r
-        \r
-        final Set<GroupingDefinition> groupings = dataNode.getGroupings();\r
-        if (groupings != null) {\r
-            for (GroupingDefinition grouping : groupings) {\r
-                traverse(grouping);\r
-            }\r
-        }\r
-    }\r
-    \r
-\r
-    private void traverseModule(Module module) {\r
-        final Set<NotificationDefinition> notifications = module.getNotifications();\r
-        for (NotificationDefinition notificationDefinition : notifications) {\r
-            traverse(notificationDefinition);\r
-        }\r
-        final Set<RpcDefinition> rpcs = module.getRpcs();\r
-        for (RpcDefinition rpcDefinition : rpcs) {\r
-            ContainerSchemaNode input = rpcDefinition.getInput();\r
-            if(input != null) {\r
-                traverse(input);\r
-            }\r
-            ContainerSchemaNode output = rpcDefinition.getInput();\r
-            if(input != null) {\r
-                traverse(output);\r
-            }\r
-        }\r
-    }\r
-    \r
-    @Override\r
-    public boolean hasNext() {\r
-        if (container.getChildNodes() != null) {\r
-            final Set<DataSchemaNode> childNodes = container.getChildNodes();\r
-\r
-            if ((childNodes != null) && !childNodes.isEmpty()) {\r
-                return childNodes.iterator().hasNext();\r
-            }\r
-        }\r
-        return false;\r
-    }\r
-\r
-    @Override\r
-    public DataSchemaNode next() {\r
-        return allChilds.iterator().next();\r
-    }\r
-\r
-    @Override\r
-    public void remove() {\r
-        throw new UnsupportedOperationException();\r
-    }\r
-}\r
+/*
+ * Copyright (c) 2013 Cisco Systems, Inc. and others.  All rights reserved.
+ *
+ * This program and the accompanying materials are made available under the
+ * terms of the Eclipse Public License v1.0 which accompanies this distribution,
+ * and is available at http://www.eclipse.org/legal/epl-v10.html
+ */
+package org.opendaylight.yangtools.yang.model.util;
+
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Set;
+
+import org.opendaylight.yangtools.yang.model.api.*;
+
+public class DataNodeIterator implements Iterator<DataSchemaNode> {
+
+    private final DataNodeContainer container;
+    private final List<ListSchemaNode> allLists;
+    private final List<ContainerSchemaNode> allContainers;
+    private final List<ChoiceNode> allChoices;
+    private final List<DataSchemaNode> allChilds;
+
+    public DataNodeIterator(final DataNodeContainer container) {
+        if (container == null) {
+            throw new IllegalArgumentException("Data Node Container MUST be specified and cannot be NULL!");
+        }
+
+        this.allContainers = new ArrayList<>();
+        this.allLists = new ArrayList<>();
+        this.allChilds = new ArrayList<>();
+        this.allChoices = new ArrayList<>();
+
+        this.container = container;
+        traverse(this.container);
+    }
+
+    public List<ContainerSchemaNode> allContainers() {
+        return allContainers;
+    }
+
+    public List<ListSchemaNode> allLists() {
+        return allLists;
+    }
+
+    public List<ChoiceNode> allChoices() {
+        return allChoices;
+    }
+
+    private void traverse(final DataNodeContainer dataNode) {
+        if (dataNode == null) {
+            return;
+        }
+
+        final Set<DataSchemaNode> childNodes = dataNode.getChildNodes();
+        if (childNodes != null) {
+            for (DataSchemaNode childNode : childNodes) {
+                if (childNode.isAugmenting()) {
+                    continue;
+                }
+                allChilds.add(childNode);
+                if (childNode instanceof ContainerSchemaNode) {
+                    final ContainerSchemaNode containerNode = (ContainerSchemaNode) childNode;
+                    allContainers.add(containerNode);
+                    traverse(containerNode);
+                } else if (childNode instanceof ListSchemaNode) {
+                    final ListSchemaNode list = (ListSchemaNode) childNode;
+                    allLists.add(list);
+                    traverse(list);
+                } else if (childNode instanceof ChoiceNode) {
+                    final ChoiceNode choiceNode = (ChoiceNode) childNode;
+                    allChoices.add(choiceNode);
+                    final Set<ChoiceCaseNode> cases = choiceNode.getCases();
+                    if (cases != null) {
+                        for (final ChoiceCaseNode caseNode : cases) {
+                            traverse(caseNode);
+                        }
+                    }
+                }
+            }
+        }
+
+        traverseModule(dataNode);
+        traverseGroupings(dataNode);
+
+    }
+
+    private void traverseModule(DataNodeContainer dataNode) {
+        final Module module;
+        if (dataNode instanceof Module) {
+            module = (Module) dataNode;
+        } else {
+            return;
+        }
+        final Set<NotificationDefinition> notifications = module.getNotifications();
+        for (NotificationDefinition notificationDefinition : notifications) {
+            traverse(notificationDefinition);
+        }
+        final Set<RpcDefinition> rpcs = module.getRpcs();
+        for (RpcDefinition rpcDefinition : rpcs) {
+            ContainerSchemaNode input = rpcDefinition.getInput();
+            if (input != null) {
+                traverse(input);
+            }
+            ContainerSchemaNode output = rpcDefinition.getInput();
+            if (input != null) {
+                traverse(output);
+            }
+        }
+    }
+
+    private void traverseGroupings(DataNodeContainer dataNode) {
+        final Set<GroupingDefinition> groupings = dataNode.getGroupings();
+        if (groupings != null) {
+            for (GroupingDefinition grouping : groupings) {
+                traverse(grouping);
+            }
+        }
+    }
+
+    @Override
+    public boolean hasNext() {
+        if (container.getChildNodes() != null) {
+            final Set<DataSchemaNode> childNodes = container.getChildNodes();
+
+            if ((childNodes != null) && !childNodes.isEmpty()) {
+                return childNodes.iterator().hasNext();
+            }
+        }
+        return false;
+    }
+
+    @Override
+    public DataSchemaNode next() {
+        return allChilds.iterator().next();
+    }
+
+    @Override
+    public void remove() {
+        throw new UnsupportedOperationException();
+    }
+}