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.CsvRightPad;
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
18
19
20
21
22
23 public class RightPadFactory implements ConversionProcessorFactory<CsvRightPad> {
24
25 @Override
26 public Optional<CellProcessor> create(final CsvRightPad 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, MessageBuilder.create("anno.attr.min")
31 .var("property", field.getNameWithClass())
32 .varWithAnno("anno", anno.annotationType())
33 .var("attrName", "size")
34 .var("attrValue", anno.size())
35 .var("min", 1)
36 .format());
37 }
38
39 final RightPadnversion/RightPad.html#RightPad">RightPad processor = next.map(n -> new RightPad(anno.size(), anno.padChar(), (StringCellProcessor)n))
40 .orElseGet(() -> new RightPad(anno.size(), anno.padChar()));
41
42 return Optional.of(processor);
43 }
44
45 }