KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > prefuse > util > collections > CompositeIntIterator


1 package prefuse.util.collections;
2
3 import java.util.NoSuchElementException JavaDoc;
4
5 /**
6  * IntIterator implementation that combines the results of multiple
7  * int iterators.
8  *
9  * @author <a HREF="http://jheer.org">jeffrey heer</a>
10  */

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     /**
26      * @see prefuse.util.collections.IntIterator#nextInt()
27      */

28     public int nextInt() {
29         if ( hasNext() ) {
30             return m_iters[m_cur].nextInt();
31         } else {
32             throw new NoSuchElementException JavaDoc();
33         }
34     }
35
36     /**
37      * @see java.util.Iterator#hasNext()
38      */

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 JavaDoc();
55     }
56
57 } // end of class CompositeIntIterator
58
Popular Tags