View Javadoc
1   package com.github.mygreen.supercsv.builder.standard;
2   
3   import java.util.Optional;
4   
5   import com.github.mygreen.supercsv.annotation.format.CsvBooleanFormat;
6   import com.github.mygreen.supercsv.builder.AbstractProcessorBuilder;
7   import com.github.mygreen.supercsv.builder.Configuration;
8   import com.github.mygreen.supercsv.builder.FieldAccessor;
9   import com.github.mygreen.supercsv.cellprocessor.format.BooleanFormatter;
10  import com.github.mygreen.supercsv.cellprocessor.format.TextFormatter;
11  
12  
13  /**
14   * boolean/Boolean型のビルダクラス。
15   * 
16   * @version 2.0
17   * @author T.TSUCHIE
18   *
19   */
20  public class BooleanProcessorBuilder extends AbstractProcessorBuilder<Boolean> {
21      
22      @Override
23      protected TextFormatter<Boolean> getDefaultFormatter(final FieldAccessor field, final Configuration config) {
24          
25          final Optional<CsvBooleanFormat> formatAnno = field.getAnnotation(CsvBooleanFormat.class);
26          
27          final BooleanFormattertter.html#BooleanFormatter">BooleanFormatter formatter = formatAnno.map(anno -> new BooleanFormatter(anno.readForTrue(), anno.readForFalse(),
28                  anno.writeAsTrue(), anno.writeAsFalse(), anno.ignoreCase(), anno.failToFalse()))
29                  .orElseGet(() -> new BooleanFormatter());
30          
31          formatAnno.ifPresent(a -> formatter.setValidationMessage(a.message()));
32          
33          return formatter;
34      }
35      
36  }