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