Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
TableRow |
|
| 2.111111111111111;2.111 |
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.List; | |
15 | ||
16 | /** | |
17 | * Represents a table row. | |
18 | * | |
19 | * @author Ketan Padegaonkar <KetanPadegaonkar [at] gmail [dot] com> | |
20 | * @version $Id$ | |
21 | */ | |
22 | public class TableRow { | |
23 | ||
24 | private final List<String> tableColumns; | |
25 | ||
26 | /** | |
27 | * Constructs an empty table row. | |
28 | */ | |
29 | public TableRow() { | |
30 | 16 | this(32); |
31 | 16 | } |
32 | ||
33 | /** | |
34 | * Constructs a row with the specified number of columns. | |
35 | * | |
36 | * @param columns the number of columns in the row. | |
37 | */ | |
38 | 45 | public TableRow(int columns) { |
39 | 45 | tableColumns = new ArrayList<String>(columns); |
40 | 45 | } |
41 | ||
42 | /** | |
43 | * Constructs a table row with the specified columns. | |
44 | * | |
45 | * @param strings the items in the row. | |
46 | */ | |
47 | public TableRow(String[] strings) { | |
48 | 29 | this(strings.length); |
49 | 95 | for (String string : strings) |
50 | 66 | tableColumns.add(string); |
51 | 29 | } |
52 | ||
53 | /** | |
54 | * Adds a column text label to the list. | |
55 | * | |
56 | * @param text the item to be added at the end of the row. | |
57 | */ | |
58 | public void add(String text) { | |
59 | 34 | tableColumns.add(text); |
60 | 34 | } |
61 | ||
62 | @Override | |
63 | public int hashCode() { | |
64 | final int prime = 31; | |
65 | 12 | int result = 1; |
66 | 12 | result = prime * result + ((tableColumns == null) ? 0 : tableColumns.hashCode()); |
67 | 12 | return result; |
68 | } | |
69 | ||
70 | @Override | |
71 | public boolean equals(Object obj) { | |
72 | 11 | if (this == obj) |
73 | 1 | return true; |
74 | 10 | if (obj == null) |
75 | 1 | return false; |
76 | 9 | if (getClass() != obj.getClass()) |
77 | 1 | return false; |
78 | 8 | final TableRow other = (TableRow) obj; |
79 | 8 | if (tableColumns.equals(other.tableColumns)) |
80 | 7 | return true; |
81 | 1 | return false; |
82 | } | |
83 | ||
84 | @Override | |
85 | public String toString() { | |
86 | 3 | return tableColumns.toString(); |
87 | } | |
88 | ||
89 | /** | |
90 | * Gets the column at the given index. | |
91 | * | |
92 | * @param index the index of the column in the row. | |
93 | * @return the text at the specified column in the row. | |
94 | */ | |
95 | public String get(int index) { | |
96 | 15 | return tableColumns.get(index); |
97 | } | |
98 | ||
99 | /** | |
100 | * Gets the number of columns. | |
101 | * | |
102 | * @return the number of columns | |
103 | */ | |
104 | public int columnCount() { | |
105 | 3 | return tableColumns.size(); |
106 | } | |
107 | ||
108 | } |