1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package com.orangesignal.csv.handlers;
18
19 import java.text.Format;
20 import java.util.Arrays;
21 import java.util.List;
22 import java.util.Map;
23
24 import com.orangesignal.csv.bean.AbstractCsvBeanTemplate;
25 import com.orangesignal.csv.bean.CsvValueConverter;
26 import com.orangesignal.csv.filters.BeanFilter;
27
28
29
30
31
32
33
34
35
36 public abstract class AbstractBeanListHandler<T, O extends AbstractCsvBeanTemplate<T, O>, H extends AbstractBeanListHandler<T, O, H>> extends AbstractCsvListHandler<T, H> {
37
38
39
40
41 protected final O template;
42
43
44
45
46 protected BeanFilter beanFilter;
47
48
49
50
51 protected List<BeanOrder> orders;
52
53
54
55
56
57
58
59
60
61 protected AbstractBeanListHandler(final O template) {
62 if (template == null) {
63 throw new IllegalArgumentException("AbstractCsvBeanTemplate must not be null");
64 }
65 this.template = template;
66 }
67
68
69
70
71 @Override
72 public List<T> processScalar(final List<T> beans) {
73 if (orders != null) {
74 BeanOrderComparator.sort(beans, orders);
75 }
76 return super.processScalar(beans);
77 }
78
79
80
81
82
83
84
85
86 public Class<T> getType() { return template.getType(); }
87
88
89
90
91
92
93
94
95 public void setValueParserMapping(final Map<String, Format> valueParserMapping) {
96 template.setValueParserMapping(valueParserMapping);
97 }
98
99
100
101
102
103
104
105
106
107 @SuppressWarnings("unchecked")
108 public H valueParserMapping(final Map<String, Format> valueParserMapping) {
109 setValueParserMapping(valueParserMapping);
110 return (H) this;
111 }
112
113
114
115
116
117
118
119
120 public void setValueFormatterMapping(final Map<Object, Format> valueFormatterMapping) {
121 template.setValueFormatterMapping(valueFormatterMapping);
122 }
123
124
125
126
127
128
129
130
131
132 @SuppressWarnings("unchecked")
133 public H valueFormatterMapping(final Map<Object, Format> valueFormatterMapping) {
134 setValueFormatterMapping(valueFormatterMapping);
135 return (H) this;
136 }
137
138
139
140
141
142
143
144
145 public void setValueConverter(final CsvValueConverter valueConverter) {
146 template.setValueConverter(valueConverter);
147 }
148
149
150
151
152
153
154
155
156
157 @SuppressWarnings("unchecked")
158 public H valueConverter(final CsvValueConverter valueConverter) {
159 setValueConverter(valueConverter);
160 return (H) this;
161 }
162
163
164
165
166
167
168
169
170 @SuppressWarnings("unchecked")
171 public H filter(final BeanFilter beanFilter) {
172 this.beanFilter = beanFilter;
173 return (H) this;
174 }
175
176
177
178
179
180
181
182 public void setOrder(final List<BeanOrder> orders) {
183 this.orders = orders;
184 }
185
186
187
188
189
190
191
192
193 @SuppressWarnings("unchecked")
194 public H order(final BeanOrder... orders) {
195 setOrder(orders != null ? Arrays.asList(orders) : null);
196 return (H) this;
197 }
198
199 }