1 |
|
|
2 |
|
|
3 |
|
|
4 |
|
|
5 |
|
|
6 |
|
|
7 |
|
|
8 |
|
|
9 |
|
|
10 |
|
|
11 |
|
|
12 |
|
|
13 |
|
|
14 |
|
|
15 |
|
|
16 |
|
|
17 |
|
|
18 |
|
|
19 |
|
|
20 |
|
package com.xpn.xwiki.plugin.charts.source; |
21 |
|
|
22 |
|
import com.xpn.xwiki.plugin.charts.exceptions.ColumnIndexOutOfBoundsException; |
23 |
|
import com.xpn.xwiki.plugin.charts.exceptions.DataSourceException; |
24 |
|
import com.xpn.xwiki.plugin.charts.exceptions.NoHeaderColumnException; |
25 |
|
import com.xpn.xwiki.plugin.charts.exceptions.NoHeaderRowException; |
26 |
|
import com.xpn.xwiki.plugin.charts.exceptions.RowIndexOutOfBoundsException; |
27 |
|
|
|
|
| 0% |
Uncovered Elements: 90 (90) |
Complexity: 36 |
Complexity Density: 0.72 |
|
28 |
|
public class DefaultDataSource implements DataSource |
29 |
|
{ |
30 |
|
protected Number[][] data; |
31 |
|
|
32 |
|
protected String[] headerRow; |
33 |
|
|
34 |
|
protected String[] headerColumn; |
35 |
|
|
36 |
|
|
37 |
|
|
38 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
39 |
0 |
public DefaultDataSource()... |
40 |
|
{ |
41 |
0 |
data = new Number[0][0]; |
42 |
|
} |
43 |
|
|
44 |
|
|
45 |
|
|
46 |
|
|
47 |
|
@param |
48 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
49 |
0 |
public DefaultDataSource(Number[][] data)... |
50 |
|
{ |
51 |
0 |
this.data = data; |
52 |
|
} |
53 |
|
|
54 |
|
|
55 |
|
|
56 |
|
|
57 |
|
@param |
58 |
|
@param |
59 |
|
@param |
60 |
|
@throws |
61 |
|
|
|
|
| 0% |
Uncovered Elements: 18 (18) |
Complexity: 9 |
Complexity Density: 0.9 |
|
62 |
0 |
public DefaultDataSource(Number[][] data, String[] headerRow, String[] headerColumn)... |
63 |
|
{ |
64 |
0 |
if (headerColumn != null && headerColumn.length != data.length) { |
65 |
0 |
throw new IllegalArgumentException("headerColumn.length != data.length"); |
66 |
|
} |
67 |
0 |
for (int i = 0; i < data.length; i++) { |
68 |
0 |
if (headerRow != null && headerRow.length != data[i].length) { |
69 |
0 |
throw new IllegalArgumentException("headerRow.length != data[" + i + "].length"); |
70 |
0 |
} else if (headerRow == null && i > 0 && data[i].length != data[i - 1].length) { |
71 |
0 |
throw new IllegalArgumentException("data[" + i + "].length != data[" + (i - 1) + "].length"); |
72 |
|
} |
73 |
|
} |
74 |
0 |
this.data = data; |
75 |
0 |
this.headerColumn = headerColumn; |
76 |
0 |
this.headerRow = headerRow; |
77 |
|
} |
78 |
|
|
79 |
|
|
80 |
|
|
81 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
82 |
0 |
@Override... |
83 |
|
public int getRowCount() |
84 |
|
{ |
85 |
0 |
return data.length; |
86 |
|
} |
87 |
|
|
88 |
|
|
89 |
|
|
90 |
|
|
|
|
| 0% |
Uncovered Elements: 5 (5) |
Complexity: 2 |
Complexity Density: 0.67 |
|
91 |
0 |
@Override... |
92 |
|
public int getColumnCount() |
93 |
|
{ |
94 |
0 |
if (data.length > 0) { |
95 |
0 |
return data[0].length; |
96 |
|
} else { |
97 |
0 |
return 0; |
98 |
|
} |
99 |
|
} |
100 |
|
|
101 |
|
|
102 |
|
@return |
103 |
|
@throws |
104 |
|
@throws |
105 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
106 |
0 |
@Override... |
107 |
|
public Number getCell(int rowIndex, int colIndex) throws DataSourceException |
108 |
|
{ |
109 |
0 |
checkRowIndex(rowIndex); |
110 |
0 |
checkColumnIndex(colIndex); |
111 |
0 |
return data[rowIndex][colIndex]; |
112 |
|
} |
113 |
|
|
114 |
|
|
115 |
|
|
116 |
|
|
117 |
|
@throws |
118 |
|
@throws |
119 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
120 |
0 |
public void setCell(int rowIndex, int colIndex, Number content) throws DataSourceException... |
121 |
|
{ |
122 |
0 |
checkRowIndex(rowIndex); |
123 |
0 |
checkColumnIndex(colIndex); |
124 |
0 |
data[rowIndex][colIndex] = content; |
125 |
|
} |
126 |
|
|
127 |
|
|
128 |
|
@return |
129 |
|
@throws |
130 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
131 |
0 |
@Override... |
132 |
|
public Number[] getRow(int rowIndex) throws DataSourceException |
133 |
|
{ |
134 |
0 |
checkRowIndex(rowIndex); |
135 |
0 |
return data[rowIndex]; |
136 |
|
} |
137 |
|
|
138 |
|
|
139 |
|
@return |
140 |
|
@throws |
141 |
|
|
|
|
| 0% |
Uncovered Elements: 7 (7) |
Complexity: 2 |
Complexity Density: 0.4 |
|
142 |
0 |
@Override... |
143 |
|
public Number[] getColumn(int colIndex) throws DataSourceException |
144 |
|
{ |
145 |
0 |
checkColumnIndex(colIndex); |
146 |
0 |
Number[] column = new Number[getRowCount()]; |
147 |
0 |
for (int i = 0; i < getRowCount(); i++) { |
148 |
0 |
column[i] = data[i][colIndex]; |
149 |
|
} |
150 |
0 |
return column; |
151 |
|
} |
152 |
|
|
153 |
|
|
154 |
|
@return |
155 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
156 |
0 |
@Override... |
157 |
|
public Number[][] getAllCells() throws DataSourceException |
158 |
|
{ |
159 |
0 |
return data; |
160 |
|
} |
161 |
|
|
162 |
|
|
163 |
|
@return |
164 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
165 |
0 |
@Override... |
166 |
|
public boolean hasHeaderRow() throws DataSourceException |
167 |
|
{ |
168 |
0 |
return headerRow != null; |
169 |
|
} |
170 |
|
|
171 |
|
|
172 |
|
@return |
173 |
|
|
|
|
| 0% |
Uncovered Elements: 1 (1) |
Complexity: 1 |
Complexity Density: 1 |
|
174 |
0 |
@Override... |
175 |
|
public boolean hasHeaderColumn() throws DataSourceException |
176 |
|
{ |
177 |
0 |
return headerColumn != null; |
178 |
|
} |
179 |
|
|
180 |
|
|
181 |
|
@return |
182 |
|
@throws |
183 |
|
@throws |
184 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
185 |
0 |
@Override... |
186 |
|
public String getHeaderRowValue(int columnIndex) throws DataSourceException |
187 |
|
{ |
188 |
0 |
checkHeaderRow(); |
189 |
0 |
checkColumnIndex(columnIndex); |
190 |
0 |
return headerRow[columnIndex]; |
191 |
|
} |
192 |
|
|
193 |
|
|
194 |
|
@return |
195 |
|
@throws |
196 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
197 |
0 |
@Override... |
198 |
|
public String[] getHeaderRow() throws DataSourceException |
199 |
|
{ |
200 |
0 |
checkHeaderRow(); |
201 |
0 |
return headerRow; |
202 |
|
} |
203 |
|
|
204 |
|
|
205 |
|
@return |
206 |
|
@throws |
207 |
|
@throws |
208 |
|
|
|
|
| 0% |
Uncovered Elements: 3 (3) |
Complexity: 1 |
Complexity Density: 0.33 |
|
209 |
0 |
@Override... |
210 |
|
public String getHeaderColumnValue(int rowIndex) throws DataSourceException |
211 |
|
{ |
212 |
0 |
checkHeaderColumn(); |
213 |
0 |
checkRowIndex(rowIndex); |
214 |
0 |
return headerColumn[rowIndex]; |
215 |
|
} |
216 |
|
|
217 |
|
|
218 |
|
@return |
219 |
|
@throws |
220 |
|
|
|
|
| 0% |
Uncovered Elements: 2 (2) |
Complexity: 1 |
Complexity Density: 0.5 |
|
221 |
0 |
@Override... |
222 |
|
public String[] getHeaderColumn() throws DataSourceException |
223 |
|
{ |
224 |
0 |
checkHeaderColumn(); |
225 |
0 |
return headerColumn; |
226 |
|
} |
227 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 1.5 |
|
228 |
0 |
private void checkRowIndex(int rowIndex) throws RowIndexOutOfBoundsException... |
229 |
|
{ |
230 |
0 |
if (rowIndex < 0 || rowIndex >= getRowCount()) { |
231 |
0 |
throw new RowIndexOutOfBoundsException("Invalid row index: " + rowIndex); |
232 |
|
} |
233 |
|
} |
234 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 3 |
Complexity Density: 1.5 |
|
235 |
0 |
private void checkColumnIndex(int columnIndex) throws ColumnIndexOutOfBoundsException... |
236 |
|
{ |
237 |
0 |
if (columnIndex < 0 || columnIndex >= getColumnCount()) { |
238 |
0 |
throw new ColumnIndexOutOfBoundsException("Invalid column index: " + columnIndex); |
239 |
|
} |
240 |
|
} |
241 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
242 |
0 |
private void checkHeaderRow() throws DataSourceException... |
243 |
|
{ |
244 |
0 |
if (!hasHeaderRow()) { |
245 |
0 |
throw new NoHeaderRowException(); |
246 |
|
} |
247 |
|
} |
248 |
|
|
|
|
| 0% |
Uncovered Elements: 4 (4) |
Complexity: 2 |
Complexity Density: 1 |
|
249 |
0 |
private void checkHeaderColumn() throws DataSourceException... |
250 |
|
{ |
251 |
0 |
if (!hasHeaderColumn()) { |
252 |
0 |
throw new NoHeaderColumnException(); |
253 |
|
} |
254 |
|
} |
255 |
|
} |