View Javadoc
1   package com.github.mygreen.supercsv.builder;
2   
3   import com.github.mygreen.supercsv.annotation.conversion.CsvFixedSize;
4   import com.github.mygreen.supercsv.cellprocessor.conversion.PaddingProcessor;
5   
6   /**
7    * アノテーション{@link CsvFixedSize}を元に、ヘッダーラベル情報を処理します。
8    * <p>パディング文字がゼロ埋めのときや、文字数を超えたとき切り出す設定の場合、
9    *    意図した結果とならない場合があるため、このクラスを参考に各自実装してください。
10   * </p>
11   * 
12   * @version 2.5
13   * @since 2.1
14   * @author T.TSUCHIE
15   *
16   */
17  public class FixedSizeHeaderMapper implements HeaderMapper {
18      
19      @Override
20      public String toMap(final ColumnMapping column, final Configuration config, final Class<?>[] groups) {
21          
22          FixedSizeColumnProperty fixedSizeProperty = column.getFixedSizeProperty();
23          if (fixedSizeProperty == null) {
24              // 固定長カラムでない場合
25              return column.getLabel();
26          }
27          
28          final PaddingProcessor paddingProcessor = fixedSizeProperty.getPaddingProcessor();
29          String label = paddingProcessor.pad(column.getLabel(),
30                  fixedSizeProperty.getSize(), fixedSizeProperty.getPadChar(),
31                  fixedSizeProperty.isRightAlign(), fixedSizeProperty.isChopped());
32          
33          return label;
34      }
35      
36  }