1 package com.github.mygreen.supercsv.validation;
2
3 import java.util.HashMap;
4 import java.util.Map;
5
6 import org.supercsv.util.CsvContext;
7
8 import com.github.mygreen.supercsv.cellprocessor.format.TextPrinter;
9
10
11
12
13
14
15
16
17 @FunctionalInterface
18 public interface CsvFieldValidator<T> {
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35 default Map<String, Object> createMessageVariables(final CsvField<T> field) {
36
37 final CsvContext csvContext = field.getValidationContext().getCsvContext();
38
39 final Map<String, Object> variables = new HashMap<>();
40 variables.put("lineNumber", csvContext.getLineNumber());
41 variables.put("rowNumber", csvContext.getRowNumber());
42 variables.put("columnNumber", field.getColumnNumber());
43 variables.put("label", field.getLabel());
44 variables.put("validatedValue", field.getValue());
45 variables.put("printer", field.getColumnMapping().getFormatter());
46
47 return variables;
48
49 }
50
51
52
53
54
55
56 void validate(CsvBindingErrors bindingErrors, CsvField<T> field);
57
58 }