Coverage Report - org.eclipse.swtbot.swt.finder.utils.TableCollection
 
Classes in this File Line Coverage Branch Coverage Complexity
TableCollection
94%
36/38
93%
15/16
2.083
 
 1  
 /*******************************************************************************
 2  
  * Copyright (c) 2008 Ketan Padegaonkar and others.
 3  
  * All rights reserved. This program and the accompanying materials
 4  
  * are made available under the terms of the Eclipse Public License v1.0
 5  
  * which accompanies this distribution, and is available at
 6  
  * http://www.eclipse.org/legal/epl-v10.html
 7  
  *
 8  
  * Contributors:
 9  
  *     Ketan Padegaonkar - initial API and implementation
 10  
  *******************************************************************************/
 11  
 package org.eclipse.swtbot.swt.finder.utils;
 12  
 
 13  
 import java.util.ArrayList;
 14  
 import java.util.Iterator;
 15  
 import java.util.List;
 16  
 
 17  
 /**
 18  
  * Represents a table.
 19  
  *
 20  
  * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com>
 21  
  * @version $Id$
 22  
  */
 23  
 public class TableCollection {
 24  
 
 25  
         private final List<TableRow>        rows;
 26  
 
 27  
         /**
 28  
          * @param tableRow the rows in the table.
 29  
          */
 30  
         public TableCollection(TableRow tableRow) {
 31  0
                 this(new TableRow[] { tableRow });
 32  0
         }
 33  
 
 34  
         /**
 35  
          * Cosntructs the table collection with the given table rows as an array.
 36  
          *
 37  
          * @param tableRows the rows in the table.
 38  
          */
 39  
         public TableCollection(TableRow[] tableRows) {
 40  9
                 this(tableRows.length);
 41  27
                 for (TableRow tableRow : tableRows)
 42  18
                         add(tableRow);
 43  9
         }
 44  
 
 45  
         /**
 46  
          * Creates an empty table.
 47  
          */
 48  
         public TableCollection() {
 49  17
                 this(32);
 50  17
         }
 51  
 
 52  
         /**
 53  
          * Creates a table with the specified number of rows.
 54  
          *
 55  
          * @param rowCount the number of rows.
 56  
          */
 57  26
         public TableCollection(int rowCount) {
 58  26
                 rows = new ArrayList<TableRow>(rowCount);
 59  26
         }
 60  
 
 61  
         /**
 62  
          * Adds a new row to the table collection.
 63  
          *
 64  
          * @param tableRow the row to be added at the end of the table.
 65  
          * @return a reference to this object.
 66  
          */
 67  
         public TableCollection add(TableRow tableRow) {
 68  29
                 rows.add(tableRow);
 69  29
                 return this;
 70  
         }
 71  
 
 72  
         /**
 73  
          * Gets the row count.
 74  
          *
 75  
          * @return the number of rows in the selection.
 76  
          */
 77  
         public int rowCount() {
 78  8
                 return rows.size();
 79  
         }
 80  
 
 81  
         /**
 82  
          * Gets the string data for the given row/column index.
 83  
          *
 84  
          * @param row the index of the row.
 85  
          * @param column the column in the row.
 86  
          * @return the string at the specified cell in the collection.
 87  
          */
 88  
         public String get(int row, int column) {
 89  11
                 return get(row).get(column);
 90  
         }
 91  
 
 92  
         /**
 93  
          * Gets the row at the given index.
 94  
          *
 95  
          * @param row the row index.
 96  
          * @return the row at the index.
 97  
          */
 98  
         public TableRow get(int row) {
 99  13
                 return rows.get(row);
 100  
         }
 101  
 
 102  
         /**
 103  
          * Gets the column count.
 104  
          *
 105  
          * @return the number of columns
 106  
          */
 107  
         public int columnCount() {
 108  4
                 if (rowCount() > 0)
 109  2
                         return rows.get(0).columnCount();
 110  2
                 return 0;
 111  
         }
 112  
 
 113  
         @Override
 114  
         public String toString() {
 115  1
                 final StringBuffer buf = new StringBuffer();
 116  4
                 for (final Iterator<TableRow> iterator = rows.iterator(); iterator.hasNext();) {
 117  2
                         final TableRow row = iterator.next();
 118  2
                         buf.append(row);
 119  2
                         buf.append("\n"); //$NON-NLS-1$
 120  
                 }
 121  1
                 return buf.toString();
 122  
         }
 123  
 
 124  
         @Override
 125  
         public int hashCode() {
 126  
                 final int prime = 31;
 127  4
                 int result = 1;
 128  4
                 result = prime * result + ((rows == null) ? 0 : rows.hashCode());
 129  4
                 return result;
 130  
         }
 131  
 
 132  
         @Override
 133  
         public boolean equals(Object obj) {
 134  9
                 if (this == obj)
 135  1
                         return true;
 136  8
                 if (obj == null)
 137  1
                         return false;
 138  7
                 if (getClass() != obj.getClass())
 139  1
                         return false;
 140  6
                 final TableCollection other = (TableCollection) obj;
 141  6
                 if (rows.equals(other.rows))
 142  5
                         return true;
 143  1
                 return false;
 144  
         }
 145  
 }