KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > jimm > datavision > source > ColumnIterator


1 package jimm.datavision.source;
2 import java.util.Iterator JavaDoc;
3 import java.util.NoSuchElementException JavaDoc;
4
5 /**
6  * An iterator over the columns in a list of tables. Not used by all data
7  * sources.
8  */

9 public class ColumnIterator implements Iterator JavaDoc {
10
11 Iterator JavaDoc tableIter;
12 Table table;
13 Iterator JavaDoc colIter;
14 Object JavaDoc nextCol;
15
16 /**
17  * Constructor.
18  */

19 public ColumnIterator(Iterator JavaDoc tableIter) {
20     this.tableIter = tableIter;
21     findNext();
22 }
23
24 public boolean hasNext() {
25     return nextCol != null;
26 }
27
28 public Object JavaDoc next() throws NoSuchElementException JavaDoc {
29     if (nextCol == null)
30     throw new NoSuchElementException JavaDoc();
31
32     Object JavaDoc returnValue = nextCol;
33     findNext(); // Fill nextCol for next time
34
return returnValue;
35 }
36
37 public void remove() throws UnsupportedOperationException JavaDoc {
38     throw new UnsupportedOperationException JavaDoc();
39 }
40
41 /**
42  * Sets <var>col</var> to the next available column. If there is none,
43  * <var>col</var> will be set to <code>null</code>.
44  */

45 protected void findNext() {
46     nextCol = null;
47
48     if (colIter == null) { // First time through
49
if (!tableIter.hasNext()) // No more tables
50
return; // nextCol will be null
51
table = (Table)tableIter.next();
52     colIter = table.columns();
53     }
54
55     while (!colIter.hasNext()) {
56     if (!tableIter.hasNext()) // No more tables
57
return; // nextCol will be null
58
table = (Table)tableIter.next();
59     colIter = table.columns();
60     }
61
62     nextCol = (Column)colIter.next();
63 }
64
65 }
66
Popular Tags