X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=yang%2Fyang-model-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fyangtools%2Fyang%2Fmodel%2Futil%2FDataNodeIterator.java;h=02b81df296394f04a7dbdd73cdba81340ca5db75;hb=37962d89fbd4032653b3918921181377c855b598;hp=518d6d8a894c502f8faaceda7e234a970bbe4de9;hpb=86112e9a601385b5e52252dc1a66ab66b857b73f;p=yangtools.git diff --git a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java index 518d6d8a89..02b81df296 100644 --- a/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java +++ b/yang/yang-model-util/src/main/java/org/opendaylight/yangtools/yang/model/util/DataNodeIterator.java @@ -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; @@ -22,15 +22,26 @@ import org.opendaylight.yangtools.yang.model.api.ListSchemaNode; import org.opendaylight.yangtools.yang.model.api.Module; 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. + * + * Iterator instance is eagerly created, walking happens on initialization. + * + * Iteration is not ordered. + * + */ public class DataNodeIterator implements Iterator { private final DataNodeContainer container; private final List allLists; private final List allContainers; - private final List allChoices; + private final List allChoices; private final List allChilds; private final List allGroupings; + private final List> allTypedefs; public DataNodeIterator(final DataNodeContainer container) { if (container == null) { @@ -42,33 +53,63 @@ public class DataNodeIterator implements Iterator { this.allChilds = new ArrayList<>(); this.allChoices = new ArrayList<>(); this.allGroupings = new ArrayList<>(); + this.allTypedefs = new ArrayList<>(); this.container = container; traverse(this.container); } + /** + * Returns list all containers present in subtree. + * + * @return Returns list all containers present in subtree. + */ public List allContainers() { return allContainers; } + /** + * Returns list all lists present in subtree. + * + * @return Returns list all containers present in subtree. + */ public List allLists() { return allLists; } - public List allChoices() { + /** + * Returns list all choices present in subtree. + * + * @return Returns list all containers present in subtree. + */ + public List allChoices() { return allChoices; } + /** + * Returns list all groupings present in subtree. + * + * @return Returns list all containers present in subtree. + */ public List allGroupings() { return allGroupings; } + /** + * Returns list all typedefs present in subtree. + * + * @return Returns list all containers present in subtree. + */ + public List> allTypedefs() { + return allTypedefs; + } + private void traverse(final DataNodeContainer dataNode) { if (dataNode == null) { return; } - final Set childNodes = dataNode.getChildNodes(); + final Iterable childNodes = dataNode.getChildNodes(); if (childNodes != null) { for (DataSchemaNode childNode : childNodes) { if (childNode.isAugmenting()) { @@ -83,8 +124,8 @@ public class DataNodeIterator implements Iterator { 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 cases = choiceNode.getCases(); if (cases != null) { @@ -96,36 +137,40 @@ public class DataNodeIterator implements Iterator { } } + this.allTypedefs.addAll(dataNode.getTypeDefinitions()); traverseModule(dataNode); traverseGroupings(dataNode); } - private void traverseModule(DataNodeContainer dataNode) { + private void traverseModule(final DataNodeContainer dataNode) { final Module module; if (dataNode instanceof Module) { module = (Module) dataNode; } else { return; } + final Set notifications = module.getNotifications(); for (NotificationDefinition notificationDefinition : notifications) { traverse(notificationDefinition); } + final Set rpcs = module.getRpcs(); for (RpcDefinition rpcDefinition : rpcs) { + this.allTypedefs.addAll(rpcDefinition.getTypeDefinitions()); ContainerSchemaNode input = rpcDefinition.getInput(); 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 groupings = dataNode.getGroupings(); if (groupings != null) { for (GroupingDefinition grouping : groupings) { @@ -138,7 +183,7 @@ public class DataNodeIterator implements Iterator { @Override public boolean hasNext() { if (container.getChildNodes() != null) { - final Set childNodes = container.getChildNodes(); + final Collection childNodes = container.getChildNodes(); if ((childNodes != null) && !childNodes.isEmpty()) { return childNodes.iterator().hasNext();