1 package com.github.mygreen.supercsv.cellprocessor.conversion;
2
3 import java.util.Arrays;
4 import java.util.Optional;
5 import java.util.Set;
6 import java.util.stream.Collectors;
7
8 import org.supercsv.cellprocessor.ift.CellProcessor;
9 import org.supercsv.cellprocessor.ift.StringCellProcessor;
10
11 import com.github.mygreen.supercsv.annotation.conversion.CsvNullConvert;
12 import com.github.mygreen.supercsv.builder.Configuration;
13 import com.github.mygreen.supercsv.builder.FieldAccessor;
14 import com.github.mygreen.supercsv.cellprocessor.ConversionProcessorFactory;
15 import com.github.mygreen.supercsv.cellprocessor.format.TextFormatter;
16
17
18
19
20
21
22
23
24 public class NullConvertFactory implements ConversionProcessorFactory<CsvNullConvert> {
25
26 @Override
27 public Optional<CellProcessor> create(final CsvNullConvert anno, final Optional<CellProcessor> next,
28 final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
29
30 final Set<String> tokens = Arrays.stream(anno.value())
31 .collect(Collectors.toSet());
32
33 final NullConvertrsion/NullConvert.html#NullConvert">NullConvert processor = next.map(n -> new NullConvert(tokens, anno.ignoreCase(), (StringCellProcessor)n))
34 .orElseGet(() -> new NullConvert(tokens, anno.ignoreCase()));
35
36 return Optional.of(processor);
37 }
38
39 }