1 22 23 24 package org.xquark.xpath; 25 26 import java.util.ArrayList ; 27 import java.util.Iterator ; 28 import java.util.NoSuchElementException ; 29 30 33 public class XTreeIterator implements Iterator 34 { 35 private static final String RCSRevision = "$Revision: 1.1 $"; 36 private static final String RCSName = "$Name: $"; 37 private ArrayList childIterators = new ArrayList (); 38 private XTreeNode nextNode; 39 private Iterator it; 40 41 42 public XTreeIterator(XTree tree) 43 { 44 nextNode = tree.getRoot(); 45 } 46 47 48 public XTreeIterator(XTreeNode iterationRoot) 49 { 50 nextNode = iterationRoot; 51 } 52 53 60 public boolean hasNext() 61 { 62 return nextNode != null; 63 } 64 65 71 public Object next() 72 { 73 if (!hasNext()) 74 throw new NoSuchElementException (); 75 XTreeNode wNode = nextNode; 77 nextNode = null; 78 79 81 if ((wNode.getChildren() != null) && !wNode.getChildren().isEmpty()) 83 { 84 childIterators.add(it); 85 it = wNode.getChildren().iterator(); 86 nextNode = (XTreeNode)it.next(); 87 } 88 else { 90 while (!childIterators.isEmpty() && (nextNode == null)) 91 { 92 if (it.hasNext()) 93 nextNode = (XTreeNode)it.next(); 94 else 95 it = (Iterator )childIterators.remove(childIterators.size() - 1); 96 } 97 } 98 return wNode; 99 } 100 101 117 public void remove() 118 { 119 throw new UnsupportedOperationException (); 120 } 121 122 } 123 | Popular Tags |