View Javadoc
1   /*
2    * CSVeed (https://github.com/42BV/CSVeed)
3    *
4    * Copyright 2013-2023 CSVeed.
5    *
6    * All rights reserved. This program and the accompanying materials
7    * are made available under the terms of The Apache Software License,
8    * Version 2.0 which accompanies this distribution, and is available at
9    * https://www.apache.org/licenses/LICENSE-2.0.txt
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   * The Class ColumnIndexMapper.
23   *
24   * @param <T>
25   *            the generic type
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  }