1
2
3
4
5
6
7
8
9
10
11
12
13
14 package olg.csv.base;
15
16 import java.util.ArrayList;
17 import java.util.Iterator;
18 import java.util.List;
19
20
21
22
23
24
25
26
27 public class Row implements Iterable<Cell> {
28
29
30
31 private final int num;
32
33
34
35
36 private final List<Cell> cells;
37
38
39
40
41 private final int size;
42
43
44
45
46
47 public boolean isEmpty() {
48 boolean retour = true;
49 if (!(cells == null || cells.isEmpty())) {
50
51 for (Cell cell : cells) {
52 if (!cell.isEmpty()) {
53 retour = false;
54 break;
55 }
56 }
57
58 }
59 return retour;
60 }
61
62
63
64
65
66
67
68
69
70
71
72 public Row(int num, List<Cell> cells, int size) {
73 super();
74 if (num < 1) {
75 throw new IllegalArgumentException(String.format(
76 "Row constructor argument num[%s] must be a positive integer", num));
77 }
78 if (size <= 0) {
79 throw new IllegalArgumentException(String.format(
80 "Row constructor argument size[%s] must be a not null positive integer", size));
81 }
82
83 this.num = num;
84 if (cells == null) {
85 this.cells = new ArrayList<Cell>(0);
86 } else {
87 this.cells = cells;
88 }
89
90 this.size = size;
91
92
93
94 }
95
96
97
98
99
100
101 public int getNum() {
102 return num;
103 }
104
105
106
107
108
109
110
111
112 public int getSize() {
113 return size;
114 }
115
116
117
118
119
120
121 public Iterator<Cell> iterator() {
122 return cells.iterator();
123 }
124
125
126
127
128
129
130
131
132 public Cell getCell(int num) {
133 Cell retour = null;
134 if (num >= size) {
135 throw new IllegalArgumentException(String.format("num argument[%s] must be lesser than row size[%s]", num,
136 size));
137 }
138
139 for (Cell cell : cells) {
140 if (cell.getNum() == num) {
141 retour = cell;
142 break;
143 }
144 }
145 return retour;
146 }
147
148
149
150
151
152
153
154
155
156
157 public Cell getCell(final String num) {
158 final int cellNumber = Cell.fromSheetCellNumber(num);
159
160 return getCell(cellNumber);
161
162 }
163
164
165
166
167
168
169
170 public String toString() {
171 return new StringBuilder().append("{num:").append(num).append(",size:").append(size).append(",cells:")
172 .append(cells.toString()).append("}").toString();
173 }
174
175
176
177
178
179
180
181
182 public Row copy(int num) {
183 return new Row(num, cells, size);
184 }
185 }