Enable checkstyle in yang-model-util
[yangtools.git] / yang / yang-model-util / src / main / java / org / opendaylight / yangtools / yang / model / util / DataNodeIterator.java
index ed1db9a31505fc3ca961704e002862268975ca9f..1c7543cf322d7e286cd00828b635ca54180d4334 100644 (file)
@@ -8,12 +8,12 @@
 package org.opendaylight.yangtools.yang.model.util;
 
 import java.util.ArrayList;
+import java.util.Collection;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Set;
-
 import org.opendaylight.yangtools.yang.model.api.ChoiceCaseNode;
-import org.opendaylight.yangtools.yang.model.api.ChoiceNode;
+import org.opendaylight.yangtools.yang.model.api.ChoiceSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.ContainerSchemaNode;
 import org.opendaylight.yangtools.yang.model.api.DataNodeContainer;
 import org.opendaylight.yangtools.yang.model.api.DataSchemaNode;
@@ -24,12 +24,19 @@ import org.opendaylight.yangtools.yang.model.api.NotificationDefinition;
 import org.opendaylight.yangtools.yang.model.api.RpcDefinition;
 import org.opendaylight.yangtools.yang.model.api.TypeDefinition;
 
+/**
+ * DataNodeIterator is iterator, which walks down whole YANG DataNodeContainer
+ * and walks all instances of {@link DataSchemaNode} present in subtree.
+ *
+ * <p>
+ * Iterator instance is eagerly created, walking happens on initialization. Iteration is not ordered.
+ */
 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<ChoiceSchemaNode> allChoices;
     private final List<DataSchemaNode> allChilds;
     private final List<GroupingDefinition> allGroupings;
     private final List<TypeDefinition<?>> allTypedefs;
@@ -50,22 +57,47 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
         traverse(this.container);
     }
 
+    /**
+     * Returns list all containers present in subtree.
+     *
+     * @return Returns list all containers present in subtree.
+     */
     public List<ContainerSchemaNode> allContainers() {
         return allContainers;
     }
 
+    /**
+     * Returns list all lists present in subtree.
+     *
+     * @return Returns list all containers present in subtree.
+     */
     public List<ListSchemaNode> allLists() {
         return allLists;
     }
 
-    public List<ChoiceNode> allChoices() {
+    /**
+     * Returns list all choices present in subtree.
+     *
+     * @return Returns list all containers present in subtree.
+     */
+    public List<ChoiceSchemaNode> allChoices() {
         return allChoices;
     }
 
+    /**
+     * Returns list all groupings present in subtree.
+     *
+     * @return Returns list all containers present in subtree.
+     */
     public List<GroupingDefinition> allGroupings() {
         return allGroupings;
     }
 
+    /**
+     * Returns list all typedefs present in subtree.
+     *
+     * @return Returns list all containers present in subtree.
+     */
     public List<TypeDefinition<?>> allTypedefs() {
         return allTypedefs;
     }
@@ -75,7 +107,7 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
             return;
         }
 
-        final Set<DataSchemaNode> childNodes = dataNode.getChildNodes();
+        final Iterable<DataSchemaNode> childNodes = dataNode.getChildNodes();
         if (childNodes != null) {
             for (DataSchemaNode childNode : childNodes) {
                 if (childNode.isAugmenting()) {
@@ -90,8 +122,8 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
                     final ListSchemaNode list = (ListSchemaNode) childNode;
                     allLists.add(list);
                     traverse(list);
-                } else if (childNode instanceof ChoiceNode) {
-                    final ChoiceNode choiceNode = (ChoiceNode) childNode;
+                } else if (childNode instanceof ChoiceSchemaNode) {
+                    final ChoiceSchemaNode choiceNode = (ChoiceSchemaNode) childNode;
                     allChoices.add(choiceNode);
                     final Set<ChoiceCaseNode> cases = choiceNode.getCases();
                     if (cases != null) {
@@ -109,7 +141,7 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
 
     }
 
-    private void traverseModule(DataNodeContainer dataNode) {
+    private void traverseModule(final DataNodeContainer dataNode) {
         final Module module;
         if (dataNode instanceof Module) {
             module = (Module) dataNode;
@@ -129,14 +161,14 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
             if (input != null) {
                 traverse(input);
             }
-            ContainerSchemaNode output = rpcDefinition.getInput();
-            if (input != null) {
+            ContainerSchemaNode output = rpcDefinition.getOutput();
+            if (output != null) {
                 traverse(output);
             }
         }
     }
 
-    private void traverseGroupings(DataNodeContainer dataNode) {
+    private void traverseGroupings(final DataNodeContainer dataNode) {
         final Set<GroupingDefinition> groupings = dataNode.getGroupings();
         if (groupings != null) {
             for (GroupingDefinition grouping : groupings) {
@@ -149,7 +181,7 @@ public class DataNodeIterator implements Iterator<DataSchemaNode> {
     @Override
     public boolean hasNext() {
         if (container.getChildNodes() != null) {
-            final Set<DataSchemaNode> childNodes = container.getChildNodes();
+            final Collection<DataSchemaNode> childNodes = container.getChildNodes();
 
             if ((childNodes != null) && !childNodes.isEmpty()) {
                 return childNodes.iterator().hasNext();