View Javadoc
1   package com.github.mygreen.supercsv.builder.standard;
2   
3   import com.github.mygreen.supercsv.builder.AbstractProcessorBuilder;
4   import com.github.mygreen.supercsv.builder.Configuration;
5   import com.github.mygreen.supercsv.builder.FieldAccessor;
6   import com.github.mygreen.supercsv.cellprocessor.format.TextFormatter;
7   import com.github.mygreen.supercsv.cellprocessor.format.TextParseException;
8   
9   
10  /**
11   * char/Character型に対するビルダ
12   * 
13   * @version 2.0
14   * @author T.TSUCHIE
15   *
16   */
17  public class CharacterProcessorBuilder extends AbstractProcessorBuilder<Character> {
18      
19      @Override
20      protected TextFormatter<Character> getDefaultFormatter(final FieldAccessor field, final Configuration config) {
21          
22          return new TextFormatter<Character>() {
23              
24              @Override
25              public Character parse(final String text) {
26                  
27                  if(text.length() >= 1) {
28                      return text.charAt(0);
29                  } else {
30                      throw new TextParseException(text, field.getDeclaredClass(),
31                              "Cannot be parsed as a char as it is a String longer than 1 character");
32                  }
33              }
34              
35              @Override
36              public String print(final Character object) {
37                  return object.toString();
38              }
39              
40              @Override
41              public void setValidationMessage(String validationMessage) {
42                  // not support
43                  
44              }
45              
46          };
47      }
48      
49  }