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.CsvHalfChar;
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
14
15
16
17
18
19
20
21 public class HalfCharFactory implements ConversionProcessorFactory<CsvHalfChar> {
22
23 @Override
24 public Optional<CellProcessor> create(final CsvHalfChar anno, final Optional<CellProcessor> next,
25 final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
26
27 final CharCategory[] categories;
28 if(anno.categories().length == 0) {
29 categories = CharCategory.values();
30 } else {
31 categories = anno.categories();
32 }
33
34 final HalfCharnversion/HalfChar.html#HalfChar">HalfChar processor = next.map(n -> new HalfChar(categories, (StringCellProcessor) n))
35 .orElseGet(() -> new HalfChar(categories));
36
37 return Optional.of(processor);
38 }
39
40 }