1 package org.apache.maven.shared.dependency.tree;
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 import java.util.Iterator;
23 import java.util.List;
24 import java.util.NoSuchElementException;
25 import java.util.Stack;
26
27
28
29
30
31
32
33 public class DependencyTreePreorderIterator
34 implements Iterator<DependencyNode>
35 {
36 private Stack<DependencyNode> nodesToProcess = new Stack<DependencyNode>();
37
38 public DependencyTreePreorderIterator( DependencyNode rootNode )
39 {
40 nodesToProcess.push( rootNode );
41 }
42
43 public boolean hasNext()
44 {
45 return !nodesToProcess.isEmpty();
46 }
47
48 public DependencyNode next()
49 {
50 if ( !hasNext() )
51 {
52 throw new NoSuchElementException();
53 }
54 DependencyNode currentNode = nodesToProcess.pop();
55 List<DependencyNode> children = currentNode.getChildren();
56 if ( children != null )
57 {
58 for ( int i = children.size() - 1; i >= 0; i-- )
59 {
60 nodesToProcess.push( children.get( i ) );
61 }
62 }
63 return currentNode;
64 }
65
66
67
68
69 public void remove()
70 {
71 throw new UnsupportedOperationException();
72 }
73 }