1 19 package org.netbeans.modules.xml.catalog.lib; 20 21 import java.util.*; 22 23 28 public final class IteratorIterator implements Iterator { 29 30 private Vector iterators = new Vector(); 31 32 private Iterator current = null; private Iterator it = null; 35 38 private Object next = null; 40 44 public void add(Iterator it) { 45 assert it != null; 46 iterators.add(it); 47 } 48 49 52 public void remove() { 53 throw new UnsupportedOperationException (); 54 } 55 56 public Object next() { 57 if (hasNext()) { 58 Object tmp = next; 59 next = null; 60 return tmp; 61 } else { 62 throw new NoSuchElementException(); 63 } 64 } 65 66 public boolean hasNext() { 67 if (next != null) return true; 68 69 if (it == null) it = iterators.iterator(); 70 while (current == null) { 71 if (it.hasNext()) { 72 current = (Iterator) it.next(); 73 } else { 74 return false; 75 } 76 } 77 78 while (current.hasNext() || it.hasNext()) { 79 80 if (current.hasNext() == false) { 82 current = (Iterator) it.next(); 83 continue; 84 } else { 85 next = current.next(); 86 return true; 87 } 88 } 89 next = null; 90 return false; 91 } 92 } 93 | Popular Tags |