1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16 package org.supercsv.cellprocessor.time;
17
18 import java.time.ZoneId;
19 import java.time.format.TextStyle;
20 import java.util.Locale;
21 import java.util.Objects;
22
23 import org.supercsv.cellprocessor.CellProcessorAdaptor;
24 import org.supercsv.cellprocessor.ift.CellProcessor;
25 import org.supercsv.exception.SuperCsvCellProcessorException;
26 import org.supercsv.util.CsvContext;
27
28
29
30
31
32
33
34
35
36 public class FmtZoneId extends CellProcessorAdaptor {
37
38 private final TextStyle textStyle;
39 private final Locale locale;
40
41
42
43
44
45 public FmtZoneId() {
46 this.textStyle = null;
47 this.locale = null;
48 }
49
50
51
52
53
54
55
56
57 public FmtZoneId(final CellProcessor next) {
58 super(next);
59 this.textStyle = null;
60 this.locale = null;
61 }
62
63
64
65
66
67
68
69
70
71 public FmtZoneId(TextStyle textStyle, Locale locale) {
72 Objects.requireNonNull(textStyle);
73 Objects.requireNonNull(locale);
74 this.textStyle = textStyle;
75 this.locale = locale;
76 }
77
78
79
80
81
82
83
84
85
86
87 public FmtZoneId(final TextStyle textStyle, final Locale locale, final CellProcessor next) {
88 super(next);
89 Objects.requireNonNull(textStyle);
90 Objects.requireNonNull(locale);
91 this.textStyle = textStyle;
92 this.locale = locale;
93 }
94
95
96
97
98
99
100 public Object execute(final Object value, final CsvContext context) {
101 validateInputNotNull(value, context);
102 if( !(value instanceof ZoneId) ) {
103 throw new SuperCsvCellProcessorException(ZoneId.class, value, context, this);
104 }
105 final ZoneId zoneId = (ZoneId) value;
106 final String result;
107 if (textStyle != null && locale != null) {
108 result = zoneId.getDisplayName(textStyle, locale);
109 } else {
110 result = zoneId.toString();
111 }
112 return next.execute(result, context);
113 }
114
115 }