1 61 62 63 package org.jaxen.util; 64 65 import java.util.ArrayList ; 66 import java.util.Iterator ; 67 import java.util.List ; 68 import java.util.NoSuchElementException ; 69 70 public class LinkedIterator implements Iterator 71 { 72 private List iterators; 73 private int cur; 74 75 public LinkedIterator() 76 { 77 this.iterators = new ArrayList (); 78 this.cur = 0; 79 } 80 81 public void addIterator(Iterator i) 82 { 83 this.iterators.add( i ); 84 } 85 86 public boolean hasNext() 87 { 88 boolean has = false; 89 90 if ( this.cur < this.iterators.size() ) 91 { 92 has = ((Iterator )this.iterators.get( this.cur )).hasNext(); 93 94 if ( ! has 95 && 96 this.cur < this.iterators.size() ) 97 { 98 ++this.cur; 99 has = hasNext(); 100 } 101 } 102 else 103 { 104 has = false; 105 } 106 107 return has; 108 } 109 110 public Object next() 111 { 112 if ( ! hasNext() ) 113 { 114 throw new NoSuchElementException (); 115 } 116 117 return ((Iterator )this.iterators.get( this.cur )).next(); 118 } 119 120 public void remove() 121 { 122 throw new UnsupportedOperationException (); 123 } 124 } 125 | Popular Tags |