Your browser does not support JavaScript and this site utilizes JavaScript to build content and provide links to additional information. You should either enable JavaScript in your browser settings or use a browser that supports JavaScript in order to take full advantage of this site.
1 package org.hibernate.util; 3 4 import java.util.Iterator ; 5 import java.util.List ; 6 7 16 public class JoinedIterator implements Iterator { 17 18 private static final Iterator [] ITERATORS = {}; 19 20 private Iterator [] iterators; 22 23 private int currentIteratorIndex; 25 26 private Iterator currentIterator; 28 29 private Iterator lastUsedIterator; 31 32 public JoinedIterator(List iterators) { 33 this( (Iterator []) iterators.toArray(ITERATORS) ); 34 } 35 36 public JoinedIterator(Iterator [] iterators) { 37 if( iterators==null ) 38 throw new NullPointerException ("Unexpected NULL iterators argument"); 39 this.iterators = iterators; 40 } 41 42 public JoinedIterator(Iterator first, Iterator second) { 43 this( new Iterator [] { first, second } ); 44 } 45 46 public boolean hasNext() { 47 updateCurrentIterator(); 48 return currentIterator.hasNext(); 49 } 50 51 public Object next() { 52 updateCurrentIterator(); 53 return currentIterator.next(); 54 } 55 56 public void remove() { 57 updateCurrentIterator(); 58 lastUsedIterator.remove(); 59 } 60 61 62 protected void updateCurrentIterator() { 65 66 if (currentIterator == null) { 67 if( iterators.length==0 ) { 68 currentIterator = EmptyIterator.INSTANCE; 69 } 70 else { 71 currentIterator = iterators[0]; 72 } 73 lastUsedIterator = currentIterator; 76 } 77 78 while (! currentIterator.hasNext() && currentIteratorIndex < iterators.length - 1) { 79 currentIteratorIndex++; 80 currentIterator = iterators[currentIteratorIndex]; 81 } 82 } 83 84 } 85
| Popular Tags
|