View Javadoc
1   package com.opencsv.bean;
2   
3   /**
4    * Builder for a {@link HeaderColumnNameMappingStrategy}.
5    * This allows opencsv to introduce new options for mapping strategies
6    * while maintaining backward compatibility and without creating
7    * reams of constructors for the mapping strategy.
8    *
9    * @param <T> The type of the bean being processed
10   * @since 5.5
11   * @author Andrew Rucker Jones
12   */
13  public class HeaderColumnNameTranslateMappingStrategyBuilder<T>
14          extends AbstractMappingStrategyBuilder<T, HeaderColumnNameTranslateMappingStrategy<T>> {
15  
16      private boolean forceCorrectRecordLength = false;
17  
18      /** Default constructor. */
19      public HeaderColumnNameTranslateMappingStrategyBuilder() {}
20  
21      @Override
22      public HeaderColumnNameTranslateMappingStrategy<T> build() {
23          HeaderColumnNameTranslateMappingStrategy<T> builder = new HeaderColumnNameTranslateMappingStrategy<>(forceCorrectRecordLength);
24          if (type != null) {
25              builder.setType(type);
26          }
27          return builder;
28      }
29  
30      /**
31       * Insists that every record will be considered to be of the correct
32       * length (that is, the same number of columns as the header).
33       * <p>Excess fields at the end of a record will be ignored. Missing
34       * fields at the end of a record will be interpreted as {@code null}.
35       * This is only relevant on reading.</p>
36       * <p>If not set, incorrect record length will throw an exception. That
37       * is, the default value is {@code false}.</p>
38       *
39       * @param forceCorrectRecordLength Whether records should be forced to
40       *                                 the correct length
41       * @return {@code this}
42       */
43      public HeaderColumnNameTranslateMappingStrategyBuilder<T> withForceCorrectRecordLength(boolean forceCorrectRecordLength) {
44          this.forceCorrectRecordLength = forceCorrectRecordLength;
45          return this;
46      }
47  }