View Javadoc
1   package com.github.mygreen.supercsv.io;
2   
3   import java.time.LocalDate;
4   
5   import com.github.mygreen.supercsv.annotation.CsvBean;
6   import com.github.mygreen.supercsv.annotation.CsvColumn;
7   import com.github.mygreen.supercsv.annotation.conversion.CsvFixedSize;
8   import com.github.mygreen.supercsv.annotation.conversion.CsvFullChar;
9   import com.github.mygreen.supercsv.annotation.format.CsvDateTimeFormat;
10  import com.github.mygreen.supercsv.builder.FixedSizeHeaderMapper;
11  import com.github.mygreen.supercsv.cellprocessor.conversion.CharWidthPaddingProcessor;
12  
13  /**
14   * テスト用のBean。
15   * 固定長の名前によるマッピングのBean
16   *
17   * @since 2.1
18   * @author T.TSUCHIE
19   *
20   */
21  @CsvBean(header=false, headerMapper=FixedSizeHeaderMapper.class) // ヘッダーを固定長に処理するマッパーを指定する。
22  public class SampleLazyFixedColumnBean {
23  
24      // 右詰めする。
25      @CsvColumn(number=1)
26      @CsvFixedSize(size=5, rightAlign=true)
27      private int no;
28  
29      // 全角空白で埋める。
30      // ただし、全角は長さ=2、半角は長さ=1 として処理する。
31      @CsvColumn(label="ユーザ名")
32      @CsvFullChar
33      @CsvFixedSize(size=20, padChar=' ', paddingProcessor=CharWidthPaddingProcessor.class)
34      private String userName;
35  
36      // 他のオブジェクト型への変換を行う場合
37      @CsvColumn(label="誕生日")
38      @CsvFixedSize(size=10, padChar='_')
39      @CsvDateTimeFormat(pattern="uuuu-MM-dd")
40      private LocalDate birthDay;
41  
42      // 指定した文字長を超えた場合、切り落とす。
43      @CsvColumn(label="コメント")
44      @CsvFixedSize(size=20, rightAlign=false, chopped=true, paddingProcessor=CharWidthPaddingProcessor.class)
45      private String comment;
46  
47      public int getNo() {
48          return no;
49      }
50  
51      public void setNo(int no) {
52          this.no = no;
53      }
54  
55      public String getUserName() {
56          return userName;
57      }
58  
59      public void setUserName(String userName) {
60          this.userName = userName;
61      }
62  
63      public LocalDate getBirthDay() {
64          return birthDay;
65      }
66  
67      public void setBirthDay(LocalDate birthDay) {
68          this.birthDay = birthDay;
69      }
70  
71      public String getComment() {
72          return comment;
73      }
74  
75      public void setComment(String comment) {
76          this.comment = comment;
77      }
78  
79  }