1 package org.opendaylight.controller.yang.model.util;
3 import java.util.ArrayList;
4 import java.util.Iterator;
8 import org.opendaylight.controller.yang.model.api.ContainerSchemaNode;
9 import org.opendaylight.controller.yang.model.api.DataNodeContainer;
10 import org.opendaylight.controller.yang.model.api.DataSchemaNode;
11 import org.opendaylight.controller.yang.model.api.LeafListSchemaNode;
12 import org.opendaylight.controller.yang.model.api.LeafSchemaNode;
13 import org.opendaylight.controller.yang.model.api.ListSchemaNode;
15 public class DataNodeIterator implements Iterator<DataSchemaNode> {
17 private final DataNodeContainer container;
18 private List<ListSchemaNode> allLists;
19 private List<ContainerSchemaNode> allContainers;
20 private List<LeafSchemaNode> allLeafs;
21 private List<LeafListSchemaNode> allLeafLists;
22 private List<DataSchemaNode> allChilds;
24 public DataNodeIterator(final DataNodeContainer container) {
25 if (container == null) {
26 throw new IllegalArgumentException("Data Node Container MUST be specified and cannot be NULL!");
30 this.container = container;
31 traverse(this.container);
35 this.allContainers = new ArrayList<ContainerSchemaNode>();
36 this.allLists = new ArrayList<ListSchemaNode>();
37 this.allLeafs = new ArrayList<LeafSchemaNode>();
38 this.allLeafLists = new ArrayList<LeafListSchemaNode>();
39 this.allChilds = new ArrayList<DataSchemaNode>();
42 public List<ContainerSchemaNode> allContainers() {
46 public List<ListSchemaNode> allLists() {
50 public List<LeafSchemaNode> allLeafs() {
54 public List<LeafListSchemaNode> allLeafLists() {
58 private void traverse(final DataNodeContainer dataNode) {
59 if (dataNode == null) {
63 final Set<DataSchemaNode> childs = dataNode.getChildNodes();
65 for (DataSchemaNode childNode : childs) {
66 if (childNode.isAugmenting()) {
69 allChilds.add(childNode);
70 if (childNode instanceof ContainerSchemaNode) {
71 final ContainerSchemaNode container = (ContainerSchemaNode) childNode;
72 allContainers.add(container);
74 } else if (childNode instanceof ListSchemaNode) {
75 final ListSchemaNode list = (ListSchemaNode) childNode;
78 } else if (childNode instanceof LeafSchemaNode) {
79 final LeafSchemaNode leaf = (LeafSchemaNode) childNode;
81 } else if (childNode instanceof LeafListSchemaNode) {
82 final LeafListSchemaNode leafList = (LeafListSchemaNode) childNode;
83 allLeafLists.add(leafList);
91 public boolean hasNext() {
92 if (container.getChildNodes() != null) {
93 Set<DataSchemaNode> childs = container.getChildNodes();
95 if ((childs != null) && !childs.isEmpty()) {
96 return childs.iterator().hasNext();
103 public DataSchemaNode next() {
104 return allChilds.iterator().next();
108 public void remove() {
109 throw new UnsupportedOperationException();