View Javadoc
1   package com.github.mygreen.supercsv.cellprocessor.conversion;
2   
3   import java.util.Optional;
4   
5   import org.supercsv.cellprocessor.ift.CellProcessor;
6   import org.supercsv.cellprocessor.ift.StringCellProcessor;
7   
8   import com.github.mygreen.supercsv.annotation.conversion.CsvMultiPad;
9   import com.github.mygreen.supercsv.builder.Configuration;
10  import com.github.mygreen.supercsv.builder.FieldAccessor;
11  import com.github.mygreen.supercsv.cellprocessor.ConversionProcessorFactory;
12  import com.github.mygreen.supercsv.cellprocessor.format.TextFormatter;
13  import com.github.mygreen.supercsv.exception.SuperCsvInvalidAnnotationException;
14  import com.github.mygreen.supercsv.localization.MessageBuilder;
15  
16  /**
17   * アノテーション{@link CsvMultiPad}を元に、CellProcesssor{@link MultiPad}を作成します。
18   *
19   * @since 2.1
20   * @author T.TSUCHIE
21   *
22   */
23  public class MultiPadFactory implements ConversionProcessorFactory<CsvMultiPad> {
24      
25      @Override
26      public Optional<CellProcessor> create(final CsvMultiPad anno, final Optional<CellProcessor> next,
27              final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
28          
29          if(anno.size() <= 0) {
30              throw new SuperCsvInvalidAnnotationException(anno,
31                      MessageBuilder.create("anno.attr.min")
32                          .var("property", field.getNameWithClass())
33                          .varWithAnno("anno", anno.annotationType())
34                          .var("attrName", "size")
35                          .var("attrValue", anno.size())
36                          .var("min", 1)
37                          .format());
38          }
39          
40          final PaddingProcessorm/github/mygreen/supercsv/cellprocessor/conversion/PaddingProcessor.html#PaddingProcessor">PaddingProcessor paddingProcessor = (PaddingProcessor)config.getBeanFactory().create(anno.paddingProcessor());
41          
42          final MultiPadnversion/MultiPad.html#MultiPad">MultiPad processor = next.map(n -> new MultiPad(anno.size(), anno.padChar(), anno.rightAlign(),
43                      anno.chopped(), paddingProcessor, (StringCellProcessor)n))
44                  .orElseGet(() -> new MultiPad(anno.size(), anno.padChar(), anno.rightAlign(),
45                          anno.chopped(), paddingProcessor));
46          
47          return Optional.of(processor);
48      }
49  }