1 package jimm.datavision.source; 2 import java.util.Iterator ; 3 import java.util.NoSuchElementException ; 4 5 9 public class ColumnIterator implements Iterator { 10 11 Iterator tableIter; 12 Table table; 13 Iterator colIter; 14 Object nextCol; 15 16 19 public ColumnIterator(Iterator tableIter) { 20 this.tableIter = tableIter; 21 findNext(); 22 } 23 24 public boolean hasNext() { 25 return nextCol != null; 26 } 27 28 public Object next() throws NoSuchElementException { 29 if (nextCol == null) 30 throw new NoSuchElementException (); 31 32 Object returnValue = nextCol; 33 findNext(); return returnValue; 35 } 36 37 public void remove() throws UnsupportedOperationException { 38 throw new UnsupportedOperationException (); 39 } 40 41 45 protected void findNext() { 46 nextCol = null; 47 48 if (colIter == null) { if (!tableIter.hasNext()) return; table = (Table)tableIter.next(); 52 colIter = table.columns(); 53 } 54 55 while (!colIter.hasNext()) { 56 if (!tableIter.hasNext()) return; table = (Table)tableIter.next(); 59 colIter = table.columns(); 60 } 61 62 nextCol = (Column)colIter.next(); 63 } 64 65 } 66 | Popular Tags |