KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > displaytag > model > ColumnIterator


1 /**
2  * Licensed under the Artistic License; you may not use this file
3  * except in compliance with the License.
4  * You may obtain a copy of the License at
5  *
6  * http://displaytag.sourceforge.net/license.html
7  *
8  * THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
9  * IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
10  * WARRANTIES OF MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
11  */

12 package org.displaytag.model;
13
14 import java.util.Iterator JavaDoc;
15 import java.util.List JavaDoc;
16
17
18 /**
19  * Iterator on columns.
20  * @author Fabrizio Giustina
21  * @version $Revision: 720 $ ($Author: fgiust $)
22  */

23 public class ColumnIterator
24 {
25
26     /**
27      * current row.
28      */

29     private Row parentRow;
30
31     /**
32      * Internal iterator on header cells.
33      */

34     private Iterator JavaDoc headerIterator;
35
36     /**
37      * Internal iterator on cells.
38      */

39     private Iterator JavaDoc cellIterator;
40
41     /**
42      * Creates a new ColumnIterator given a list of column and a row.
43      * @param columns List containing column objects
44      * @param row current Row
45      */

46     public ColumnIterator(List JavaDoc columns, Row row)
47     {
48         this.headerIterator = columns.iterator();
49         this.cellIterator = row.getCellList().iterator();
50         this.parentRow = row;
51     }
52
53     /**
54      * Are there more columns?
55      * @return boolean <code>true</code> if there are more columns
56      */

57     public boolean hasNext()
58     {
59         return this.headerIterator.hasNext();
60     }
61
62     /**
63      * Returns the next column.
64      * @return Column next column
65      */

66     public Column nextColumn()
67     {
68         HeaderCell header = (HeaderCell) this.headerIterator.next();
69
70         Cell cell = Cell.EMPTY_CELL;
71
72         // if cells is not present simply return an empty cell.
73
// this is needed for automatic properties discovery
74
if (this.cellIterator.hasNext())
75         {
76             cell = (Cell) this.cellIterator.next();
77         }
78
79         // create a new column using the next value in the header and cell iterators and returns it
80
return new Column(header, cell, this.parentRow);
81     }
82
83 }
Popular Tags