1 package prefuse.util.collections; 2 3 import java.util.NoSuchElementException ; 4 5 11 public class CompositeIntIterator extends IntIterator { 12 13 private IntIterator[] m_iters; 14 private int m_cur; 15 16 public CompositeIntIterator(IntIterator iter1, IntIterator iter2) { 17 this(new IntIterator[] { iter1, iter2 }); 18 } 19 20 public CompositeIntIterator(IntIterator[] iters) { 21 m_iters = iters; 22 m_cur = 0; 23 } 24 25 28 public int nextInt() { 29 if ( hasNext() ) { 30 return m_iters[m_cur].nextInt(); 31 } else { 32 throw new NoSuchElementException (); 33 } 34 } 35 36 39 public boolean hasNext() { 40 if ( m_iters == null ) 41 return false; 42 43 while ( true ) { 44 if ( m_iters[m_cur].hasNext() ) { 45 return true; 46 } else if ( ++m_cur >= m_iters.length ) { 47 m_iters = null; 48 return false; 49 } 50 } 51 } 52 53 public void remove() { 54 throw new UnsupportedOperationException (); 55 } 56 57 } | Popular Tags |