1 package com.github.mygreen.supercsv.cellprocessor.constraint;
2
3 import java.util.Optional;
4
5 import org.supercsv.cellprocessor.ift.CellProcessor;
6
7 import com.github.mygreen.supercsv.annotation.constraint.CsvRequire;
8 import com.github.mygreen.supercsv.builder.Configuration;
9 import com.github.mygreen.supercsv.builder.FieldAccessor;
10 import com.github.mygreen.supercsv.cellprocessor.ConstraintProcessorFactory;
11 import com.github.mygreen.supercsv.cellprocessor.format.TextFormatter;
12
13
14
15
16
17
18
19
20
21 public class RequireFactory implements ConstraintProcessorFactory<CsvRequire> {
22
23 @Override
24 public Optional<CellProcessor> create(final CsvRequire anno, final Optional<CellProcessor> next,
25 final FieldAccessor field, final TextFormatter<?> formatter, final Configuration config) {
26
27 final Requireonstraint/Require.html#Require">Require processor = next.map(n -> new Require(anno.considerEmpty(), anno.considerBlank(), n))
28 .orElseGet(() -> new Require(anno.considerEmpty(), anno.considerBlank()));
29
30 processor.setValidationMessage(anno.message());
31
32 return Optional.of(processor);
33 }
34
35 }