2 * Copyright (c) 2013 Cisco Systems, Inc. and others. All rights reserved.
4 * This program and the accompanying materials are made available under the
5 * terms of the Eclipse Public License v1.0 which accompanies this distribution,
6 * and is available at http://www.eclipse.org/legal/epl-v10.html
8 package org.opendaylight.yangtools.yang.model.util;
10 import java.util.ArrayList;
11 import java.util.Iterator;
12 import java.util.List;
15 import org.opendaylight.yangtools.yang.model.api.*;
17 public class DataNodeIterator implements Iterator<DataSchemaNode> {
19 private final DataNodeContainer container;
20 private final List<ListSchemaNode> allLists;
21 private final List<ContainerSchemaNode> allContainers;
22 private final List<ChoiceNode> allChoices;
23 private final List<DataSchemaNode> allChilds;
25 public DataNodeIterator(final DataNodeContainer container) {
26 if (container == null) {
27 throw new IllegalArgumentException("Data Node Container MUST be specified and cannot be NULL!");
30 this.allContainers = new ArrayList<>();
31 this.allLists = new ArrayList<>();
32 this.allChilds = new ArrayList<>();
33 this.allChoices = new ArrayList<>();
35 this.container = container;
36 traverse(this.container);
39 public List<ContainerSchemaNode> allContainers() {
43 public List<ListSchemaNode> allLists() {
47 public List<ChoiceNode> allChoices() {
51 private void traverse(final DataNodeContainer dataNode) {
52 if (dataNode == null) {
56 final Set<DataSchemaNode> childNodes = dataNode.getChildNodes();
57 if (childNodes != null) {
58 for (DataSchemaNode childNode : childNodes) {
59 if (childNode.isAugmenting()) {
62 allChilds.add(childNode);
63 if (childNode instanceof ContainerSchemaNode) {
64 final ContainerSchemaNode container = (ContainerSchemaNode) childNode;
65 allContainers.add(container);
67 } else if (childNode instanceof ListSchemaNode) {
68 final ListSchemaNode list = (ListSchemaNode) childNode;
71 } else if (childNode instanceof ChoiceNode) {
72 final ChoiceNode choiceNode = (ChoiceNode) childNode;
73 allChoices.add(choiceNode);
74 final Set<ChoiceCaseNode> cases = choiceNode.getCases();
76 for (final ChoiceCaseNode caseNode : cases) {
84 final Set<GroupingDefinition> groupings = dataNode.getGroupings();
85 if (groupings != null) {
86 for (GroupingDefinition grouping : groupings) {
93 public boolean hasNext() {
94 if (container.getChildNodes() != null) {
95 final Set<DataSchemaNode> childNodes = container.getChildNodes();
97 if ((childNodes != null) && !childNodes.isEmpty()) {
98 return childNodes.iterator().hasNext();
105 public DataSchemaNode next() {
106 return allChilds.iterator().next();
110 public void remove() {
111 throw new UnsupportedOperationException();