KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > net > sourceforge > jwebunit > ExpectedRow


1 /********************************************************************************
2  * Copyright (c) 2001, ThoughtWorks, Inc.
3  * Distributed open-source, see full license under licenses/jwebunit_license.txt
4 **********************************/

5 package net.sourceforge.jwebunit;
6
7
8 /**
9  * Represents an expected row of an html table.
10  *
11  * @author Jim Weaver
12  */

13 public class ExpectedRow {
14
15     private ExpectedCell[] expectedCells;
16
17     /**
18      * Construct an expected row from an array of objects which specify the
19      * expected cells of the row. If an object in the array is an
20      * {@link net.sourceforge.jwebunit.ExpectedCell}, it is directly added to
21      * the expected cells of the row, otherwise an {@link net.sourceforge.jwebunit.ExpectedCell}
22      * is created from the toString() value of the object and an assumed colspan of 1.
23      *
24      * @param rowCells objects representing the row's expected cells.
25      */

26     public ExpectedRow(Object JavaDoc[] rowCells) {
27         this.expectedCells = new ExpectedCell[rowCells.length];
28         for (int i = 0; i < rowCells.length; i++) {
29             Object JavaDoc column = rowCells[i];
30             if (column instanceof ExpectedCell) {
31                 this.expectedCells[i] = (ExpectedCell)column;
32             } else {
33                 this.expectedCells[i] = new ExpectedCell(column.toString(), 1);
34             }
35         }
36     }
37
38     String JavaDoc[] getExpandedColumns() {
39         String JavaDoc[] expandedColumns = new String JavaDoc[getNumberOfColumns()];
40         int targetColumn = 0;
41         for (int i = 0; i < expectedCells.length; i++) {
42             targetColumn = expandIntoColumns(expectedCells[i], expandedColumns, targetColumn);
43         }
44         return expandedColumns;
45     }
46
47     private int getNumberOfColumns() {
48         int numCols = 0;
49         for (int i = 0; i < expectedCells.length; i++) {
50             ExpectedCell column = expectedCells[i];
51             numCols += (column).getColspan();
52         }
53         return numCols;
54     }
55
56     private int expandIntoColumns(ExpectedCell cell, String JavaDoc[] targetArray, int offset) {
57         for (int columnsSpanned = 0; columnsSpanned < cell.getColspan(); columnsSpanned++) {
58             targetArray[offset] = cell.getExpectedValue();
59             offset++;
60         }
61         return offset;
62     }
63
64 }
65
Popular Tags