1
2
3
4
5
6
7
8
9
10
11 package org.csveed.row;
12
13 import java.util.Iterator;
14
15 import org.csveed.api.Header;
16 import org.csveed.api.Row;
17 import org.csveed.common.Column;
18 import org.csveed.report.CsvException;
19 import org.csveed.report.GeneralError;
20 import org.csveed.report.RowReport;
21
22
23
24
25 public class RowImpl implements Row {
26
27
28 private Line line;
29
30
31 private Header header;
32
33
34
35
36
37
38
39
40
41 public RowImpl(Line line, Header header) {
42 this.line = line;
43 this.header = header;
44 }
45
46 @Override
47 public Header getHeader() {
48 if (this.header == null) {
49 throw new CsvException(new GeneralError(
50 "No header has been found for this file. Set @CsvFile#useHeaders to read the header"));
51 }
52 return this.header;
53 }
54
55 @Override
56 public RowReport reportOnEndOfLine() {
57 return line.reportOnEndOfLine();
58 }
59
60 @Override
61 public RowReport reportOnColumn(int columnIndex) {
62 return line.reportOnColumn(new Column(columnIndex));
63 }
64
65 @Override
66 public String get(String columnName) {
67 return line.get(header.getIndex(columnName) - 1);
68 }
69
70 @Override
71 public String getColumnName(int columnIndex) {
72 return getHeader().getName(columnIndex);
73 }
74
75 @Override
76 public boolean hasHeader() {
77 return header != null;
78 }
79
80 @Override
81 public int size() {
82 return line.size();
83 }
84
85 @Override
86 public String get(int columnIndex) {
87 return line.get(columnIndex - 1);
88 }
89
90
91
92
93
94
95 @Override
96 public Iterator<String> iterator() {
97 return line.iterator();
98 }
99
100 }