X-Git-Url: https://git.opendaylight.org/gerrit/gitweb?a=blobdiff_plain;f=opendaylight%2Fsal%2Fyang-prototype%2Fyang%2Fyang-model-util%2Fsrc%2Fmain%2Fjava%2Forg%2Fopendaylight%2Fcontroller%2Fyang%2Fmodel%2Futil%2FDataNodeIterator.java;h=d55f84923c4fd6dae5cf8bf58b08c18ba9f433f0;hb=a9e6627736e99183c5c6be4dd42ec364836acb80;hp=7c26531f37efbddd520b31623539d011511719f7;hpb=7989f1cecf0fd0d69c5b69263d80dc084db66f0c;p=controller.git diff --git a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/DataNodeIterator.java b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/DataNodeIterator.java index 7c26531f37..d55f84923c 100644 --- a/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/DataNodeIterator.java +++ b/opendaylight/sal/yang-prototype/yang/yang-model-util/src/main/java/org/opendaylight/controller/yang/model/util/DataNodeIterator.java @@ -1,3 +1,10 @@ +/* + * 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.controller.yang.model.util; import java.util.ArrayList; @@ -5,41 +12,30 @@ import java.util.Iterator; import java.util.List; import java.util.Set; -import org.opendaylight.controller.yang.model.api.ContainerSchemaNode; -import org.opendaylight.controller.yang.model.api.DataNodeContainer; -import org.opendaylight.controller.yang.model.api.DataSchemaNode; -import org.opendaylight.controller.yang.model.api.GroupingDefinition; -import org.opendaylight.controller.yang.model.api.LeafListSchemaNode; -import org.opendaylight.controller.yang.model.api.LeafSchemaNode; -import org.opendaylight.controller.yang.model.api.ListSchemaNode; +import org.opendaylight.controller.yang.model.api.*; public class DataNodeIterator implements Iterator { private final DataNodeContainer container; - private List allLists; - private List allContainers; - private List allLeafs; - private List allLeafLists; - private List allChilds; + private final List allLists; + private final List allContainers; + private final List allChoices; + private final List allChilds; public DataNodeIterator(final DataNodeContainer container) { if (container == null) { throw new IllegalArgumentException("Data Node Container MUST be specified and cannot be NULL!"); } - init(); + this.allContainers = new ArrayList<>(); + this.allLists = new ArrayList<>(); + this.allChilds = new ArrayList<>(); + this.allChoices = new ArrayList<>(); + this.container = container; traverse(this.container); } - private void init() { - this.allContainers = new ArrayList(); - this.allLists = new ArrayList(); - this.allLeafs = new ArrayList(); - this.allLeafLists = new ArrayList(); - this.allChilds = new ArrayList(); - } - public List allContainers() { return allContainers; } @@ -48,12 +44,8 @@ public class DataNodeIterator implements Iterator { return allLists; } - public List allLeafs() { - return allLeafs; - } - - public List allLeafLists() { - return allLeafLists; + public List allChoices() { + return allChoices; } private void traverse(final DataNodeContainer dataNode) { @@ -61,9 +53,9 @@ public class DataNodeIterator implements Iterator { return; } - final Set childs = dataNode.getChildNodes(); - if (childs != null) { - for (DataSchemaNode childNode : childs) { + final Set childNodes = dataNode.getChildNodes(); + if (childNodes != null) { + for (DataSchemaNode childNode : childNodes) { if (childNode.isAugmenting()) { continue; } @@ -76,19 +68,22 @@ public class DataNodeIterator implements Iterator { final ListSchemaNode list = (ListSchemaNode) childNode; allLists.add(list); traverse(list); - } else if (childNode instanceof LeafSchemaNode) { - final LeafSchemaNode leaf = (LeafSchemaNode) childNode; - allLeafs.add(leaf); - } else if (childNode instanceof LeafListSchemaNode) { - final LeafListSchemaNode leafList = (LeafListSchemaNode) childNode; - allLeafLists.add(leafList); + } else if (childNode instanceof ChoiceNode) { + final ChoiceNode choiceNode = (ChoiceNode) childNode; + allChoices.add(choiceNode); + final Set cases = choiceNode.getCases(); + if (cases != null) { + for (final ChoiceCaseNode caseNode : cases) { + traverse(caseNode); + } + } } } } final Set groupings = dataNode.getGroupings(); - if(groupings != null) { - for(GroupingDefinition grouping : groupings) { + if (groupings != null) { + for (GroupingDefinition grouping : groupings) { traverse(grouping); } } @@ -97,10 +92,10 @@ public class DataNodeIterator implements Iterator { @Override public boolean hasNext() { if (container.getChildNodes() != null) { - Set childs = container.getChildNodes(); + final Set childNodes = container.getChildNodes(); - if ((childs != null) && !childs.isEmpty()) { - return childs.iterator().hasNext(); + if ((childNodes != null) && !childNodes.isEmpty()) { + return childNodes.iterator().hasNext(); } } return false;