View Javadoc
1   package org.csveed.bean;
2   
3   import java.util.Set;
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  
11  public class ColumnIndexMapper<T> extends AbstractMapper<T> {
12  
13      @Override
14      protected Set<Column> keys() {
15          return beanInstructions.getProperties().columnIndexKeys();
16      }
17  
18      @Override
19      public BeanProperty getBeanProperty(Column currentColumn) {
20          return beanInstructions.getProperties().fromIndex(currentColumn);
21      }
22  
23      @Override
24      protected void checkKey(Header header, Column key) {
25          if (key.getColumnIndex() > header.size()) {
26              throw new CsvException(new GeneralError(
27                      "Column with index " + key + " does not exist in file with " + header.size() + " columns. " +
28                              "Originally mapped to property \"" + getBeanProperty(key).getPropertyName() + "\""
29                      ));
30          }
31      }
32  
33      @Override
34      protected Column getColumn(Row row) {
35          return new Column();
36      }
37  
38  }