1
2
3
4
5
6
7
8
9
10
11 package org.csveed.bean;
12
13 import java.util.Set;
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
21
22
23
24
25
26
27 public class ColumnIndexMapper<T> extends AbstractMapper<T> {
28
29 @Override
30 protected Set<Column> keys() {
31 return beanInstructions.getProperties().columnIndexKeys();
32 }
33
34 @Override
35 public BeanProperty getBeanProperty(Column currentColumn) {
36 return beanInstructions.getProperties().fromIndex(currentColumn);
37 }
38
39 @Override
40 protected void checkKey(Header header, Column key) {
41 if (key.getColumnIndex() > header.size()) {
42 throw new CsvException(new GeneralError(
43 "Column with index " + key + " does not exist in file with " + header.size() + " columns. "
44 + "Originally mapped to property \"" + getBeanProperty(key).getPropertyName() + "\""));
45 }
46 }
47
48 @Override
49 protected Column getColumn(Row row) {
50 return new Column();
51 }
52
53 }