01: package jimm.datavision.source;
02:
03: import java.util.Iterator;
04: import java.util.NoSuchElementException;
05:
06: /**
07: * An iterator over the columns in a list of tables. Not used by all data
08: * sources.
09: */
10: public class ColumnIterator implements Iterator {
11:
12: Iterator tableIter;
13: Table table;
14: Iterator colIter;
15: Object nextCol;
16:
17: /**
18: * Constructor.
19: */
20: public ColumnIterator(Iterator tableIter) {
21: this .tableIter = tableIter;
22: findNext();
23: }
24:
25: public boolean hasNext() {
26: return nextCol != null;
27: }
28:
29: public Object next() throws NoSuchElementException {
30: if (nextCol == null)
31: throw new NoSuchElementException();
32:
33: Object returnValue = nextCol;
34: findNext(); // Fill nextCol for next time
35: return returnValue;
36: }
37:
38: public void remove() throws UnsupportedOperationException {
39: throw new UnsupportedOperationException();
40: }
41:
42: /**
43: * Sets <var>col</var> to the next available column. If there is none,
44: * <var>col</var> will be set to <code>null</code>.
45: */
46: protected void findNext() {
47: nextCol = null;
48:
49: if (colIter == null) { // First time through
50: if (!tableIter.hasNext()) // No more tables
51: return; // nextCol will be null
52: table = (Table) tableIter.next();
53: colIter = table.columns();
54: }
55:
56: while (!colIter.hasNext()) {
57: if (!tableIter.hasNext()) // No more tables
58: return; // nextCol will be null
59: table = (Table) tableIter.next();
60: colIter = table.columns();
61: }
62:
63: nextCol = (Column) colIter.next();
64: }
65:
66: }
|