1 | |
|
2 | |
|
3 | |
|
4 | |
|
5 | |
|
6 | |
|
7 | |
|
8 | |
|
9 | |
|
10 | |
|
11 | |
|
12 | |
|
13 | |
|
14 | |
|
15 | |
|
16 | |
|
17 | |
package org.kuali.rice.shareddata.api.postalcode; |
18 | |
|
19 | |
|
20 | |
import org.apache.commons.lang.StringUtils; |
21 | |
import org.apache.commons.lang.builder.EqualsBuilder; |
22 | |
import org.apache.commons.lang.builder.HashCodeBuilder; |
23 | |
import org.apache.commons.lang.builder.ToStringBuilder; |
24 | |
import org.kuali.rice.core.api.CoreConstants; |
25 | |
import org.kuali.rice.core.api.mo.ModelBuilder; |
26 | |
import org.kuali.rice.core.api.mo.ModelObjectComplete; |
27 | |
import org.w3c.dom.Element; |
28 | |
|
29 | |
import javax.xml.bind.annotation.XmlAccessType; |
30 | |
import javax.xml.bind.annotation.XmlAccessorType; |
31 | |
import javax.xml.bind.annotation.XmlAnyElement; |
32 | |
import javax.xml.bind.annotation.XmlElement; |
33 | |
import javax.xml.bind.annotation.XmlRootElement; |
34 | |
import javax.xml.bind.annotation.XmlType; |
35 | |
import java.io.Serializable; |
36 | |
import java.util.Collection; |
37 | |
|
38 | |
|
39 | |
|
40 | |
|
41 | |
|
42 | |
|
43 | |
|
44 | |
|
45 | |
@XmlRootElement(name = PostalCode.Constants.ROOT_ELEMENT_NAME) |
46 | |
@XmlAccessorType(XmlAccessType.NONE) |
47 | |
@XmlType(name = PostalCode.Constants.TYPE_NAME, propOrder = { |
48 | |
PostalCode.Elements.CODE, |
49 | |
PostalCode.Elements.CITY_NAME, |
50 | |
PostalCode.Elements.COUNTRY_CODE, |
51 | |
PostalCode.Elements.STATE_CODE, |
52 | |
PostalCode.Elements.ACTIVE, |
53 | |
PostalCode.Elements.COUNTY_CODE, |
54 | |
CoreConstants.CommonElements.VERSION_NUMBER, |
55 | |
CoreConstants.CommonElements.FUTURE_ELEMENTS |
56 | |
}) |
57 | 3 | public final class PostalCode implements PostalCodeContract, ModelObjectComplete { |
58 | |
|
59 | |
private static final long serialVersionUID = 6097498602725305353L; |
60 | |
|
61 | |
@XmlElement(name = Elements.CODE, required = true) |
62 | |
private final String code; |
63 | |
|
64 | |
@XmlElement(name = Elements.CITY_NAME, required = false) |
65 | |
private final String cityName; |
66 | |
|
67 | |
@XmlElement(name = Elements.COUNTRY_CODE, required = true) |
68 | |
private final String countryCode; |
69 | |
|
70 | |
@XmlElement(name = Elements.STATE_CODE, required = false) |
71 | |
private final String stateCode; |
72 | |
|
73 | |
@XmlElement(name = Elements.COUNTY_CODE, required = false) |
74 | |
private final String countyCode; |
75 | |
|
76 | |
@XmlElement(name = Elements.ACTIVE, required = true) |
77 | |
private final boolean active; |
78 | |
|
79 | |
@XmlElement(name = CoreConstants.CommonElements.VERSION_NUMBER, required = false) |
80 | |
private final Long versionNumber; |
81 | |
|
82 | 5 | @SuppressWarnings("unused") |
83 | |
@XmlAnyElement |
84 | |
private final Collection<Element> _futureElements = null; |
85 | |
|
86 | |
|
87 | |
|
88 | |
|
89 | |
@SuppressWarnings("unused") |
90 | 2 | private PostalCode() { |
91 | 2 | this.code = null; |
92 | 2 | this.cityName = null; |
93 | 2 | this.countryCode = null; |
94 | 2 | this.stateCode = null; |
95 | 2 | this.countyCode = null; |
96 | 2 | this.active = false; |
97 | 2 | this.versionNumber = null; |
98 | 2 | } |
99 | |
|
100 | 3 | private PostalCode(Builder builder) { |
101 | 3 | code = builder.getCode(); |
102 | 3 | cityName = builder.getCityName(); |
103 | 3 | countryCode = builder.getCountryCode(); |
104 | 3 | stateCode = builder.getStateCode(); |
105 | 3 | countyCode = builder.getCountyCode(); |
106 | 3 | active = builder.isActive(); |
107 | 3 | versionNumber = builder.getVersionNumber(); |
108 | 3 | } |
109 | |
|
110 | |
@Override |
111 | |
public String getCode() { |
112 | 0 | return code; |
113 | |
} |
114 | |
|
115 | |
@Override |
116 | |
public String getCityName() { |
117 | 0 | return cityName; |
118 | |
} |
119 | |
|
120 | |
@Override |
121 | |
public String getCountryCode() { |
122 | 0 | return countryCode; |
123 | |
} |
124 | |
|
125 | |
@Override |
126 | |
public String getStateCode() { |
127 | 0 | return stateCode; |
128 | |
} |
129 | |
|
130 | |
@Override |
131 | |
public String getCountyCode() { |
132 | 0 | return countyCode; |
133 | |
} |
134 | |
|
135 | |
@Override |
136 | |
public boolean isActive() { |
137 | 0 | return active; |
138 | |
} |
139 | |
|
140 | |
@Override |
141 | |
public Long getVersionNumber() { |
142 | 0 | return versionNumber; |
143 | |
} |
144 | |
|
145 | |
|
146 | |
|
147 | |
|
148 | 3 | public static class Builder implements PostalCodeContract, ModelBuilder, Serializable { |
149 | |
|
150 | |
private static final long serialVersionUID = 7077484401017765844L; |
151 | |
|
152 | |
private String code; |
153 | |
private String cityName; |
154 | |
private String countryCode; |
155 | |
private String stateCode; |
156 | |
private String countyCode; |
157 | |
private boolean active; |
158 | |
private Long versionNumber; |
159 | |
|
160 | 20 | private Builder(String code, String countryCode) { |
161 | 20 | setCode(code); |
162 | 16 | setCountryCode(countryCode); |
163 | 13 | } |
164 | |
|
165 | |
|
166 | |
|
167 | |
|
168 | |
public static Builder create(String code, String countryCode) { |
169 | 18 | final Builder builder = new Builder(code, countryCode); |
170 | 11 | builder.setActive(true); |
171 | 11 | return builder; |
172 | |
} |
173 | |
|
174 | |
|
175 | |
|
176 | |
|
177 | |
public static Builder create(PostalCodeContract contract) { |
178 | 2 | final Builder builder = new Builder(contract.getCode(), contract.getCountryCode()); |
179 | 2 | builder.setActive(contract.isActive()); |
180 | 2 | builder.setVersionNumber(contract.getVersionNumber()); |
181 | 2 | if (StringUtils.isNotBlank(contract.getCountyCode())) { |
182 | 1 | builder.setCountyCode(contract.getCountyCode()); |
183 | |
} |
184 | |
|
185 | 2 | if (StringUtils.isNotBlank(contract.getCityName())) { |
186 | 1 | builder.setCityName(contract.getCityName()); |
187 | |
} |
188 | |
|
189 | 2 | if (StringUtils.isNotBlank(contract.getStateCode())) { |
190 | 1 | builder.setStateCode(contract.getStateCode()); |
191 | |
} |
192 | 2 | return builder; |
193 | |
} |
194 | |
|
195 | |
@Override |
196 | |
public String getCode() { |
197 | 4 | return code; |
198 | |
} |
199 | |
|
200 | |
|
201 | |
|
202 | |
|
203 | |
|
204 | |
|
205 | |
|
206 | |
public void setCode(String code) { |
207 | 20 | if (StringUtils.isBlank(code)) { |
208 | 4 | throw new IllegalArgumentException("code is blank"); |
209 | |
} |
210 | |
|
211 | 16 | this.code = code; |
212 | 16 | } |
213 | |
|
214 | |
@Override |
215 | |
public String getCityName() { |
216 | 4 | return cityName; |
217 | |
} |
218 | |
|
219 | |
|
220 | |
|
221 | |
|
222 | |
|
223 | |
|
224 | |
|
225 | |
public void setCityName(String cityName) { |
226 | 4 | if (StringUtils.isBlank(cityName)) { |
227 | 3 | throw new IllegalArgumentException("cityName is blank"); |
228 | |
} |
229 | |
|
230 | 1 | this.cityName = cityName; |
231 | 1 | } |
232 | |
|
233 | |
@Override |
234 | |
public String getCountryCode() { |
235 | 4 | return countryCode; |
236 | |
} |
237 | |
|
238 | |
|
239 | |
|
240 | |
|
241 | |
|
242 | |
|
243 | |
|
244 | |
|
245 | |
public void setCountryCode(String countryCode) { |
246 | 16 | if (StringUtils.isBlank(countryCode)) { |
247 | 3 | throw new IllegalArgumentException("countryCode is blank"); |
248 | |
} |
249 | |
|
250 | 13 | this.countryCode = countryCode; |
251 | 13 | } |
252 | |
|
253 | |
@Override |
254 | |
public String getStateCode() { |
255 | 4 | return stateCode; |
256 | |
} |
257 | |
|
258 | |
|
259 | |
|
260 | |
|
261 | |
|
262 | |
|
263 | |
|
264 | |
|
265 | |
public void setStateCode(String stateCode) { |
266 | 4 | if (StringUtils.isBlank(stateCode)) { |
267 | 3 | throw new IllegalArgumentException("stateCode is blank"); |
268 | |
} |
269 | |
|
270 | 1 | this.stateCode = stateCode; |
271 | 1 | } |
272 | |
|
273 | |
@Override |
274 | |
public String getCountyCode() { |
275 | 4 | return countyCode; |
276 | |
} |
277 | |
|
278 | |
|
279 | |
|
280 | |
|
281 | |
|
282 | |
|
283 | |
|
284 | |
|
285 | |
public void setCountyCode(String countyCode) { |
286 | 4 | if (StringUtils.isBlank(countyCode)) { |
287 | 3 | throw new IllegalArgumentException("countyCode is blank"); |
288 | |
} |
289 | |
|
290 | 1 | this.countyCode = countyCode; |
291 | 1 | } |
292 | |
|
293 | |
@Override |
294 | |
public boolean isActive() { |
295 | 4 | return active; |
296 | |
} |
297 | |
|
298 | |
public void setActive(boolean active) { |
299 | 13 | this.active = active; |
300 | 13 | } |
301 | |
|
302 | |
@Override |
303 | |
public Long getVersionNumber() { |
304 | 4 | return versionNumber; |
305 | |
} |
306 | |
|
307 | |
public void setVersionNumber(Long versionNumber) { |
308 | 2 | this.versionNumber = versionNumber; |
309 | 2 | } |
310 | |
|
311 | |
@Override |
312 | |
public PostalCode build() { |
313 | 3 | return new PostalCode(this); |
314 | |
} |
315 | |
} |
316 | |
|
317 | |
@Override |
318 | |
public int hashCode() { |
319 | 0 | return HashCodeBuilder.reflectionHashCode(this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
320 | |
} |
321 | |
|
322 | |
@Override |
323 | |
public boolean equals(Object obj) { |
324 | 1 | return EqualsBuilder.reflectionEquals(obj, this, Constants.HASH_CODE_EQUALS_EXCLUDE); |
325 | |
} |
326 | |
|
327 | |
@Override |
328 | |
public String toString() { |
329 | 0 | return ToStringBuilder.reflectionToString(this); |
330 | |
} |
331 | |
|
332 | |
|
333 | |
|
334 | |
|
335 | 0 | static class Constants { |
336 | |
final static String ROOT_ELEMENT_NAME = "postalCode"; |
337 | |
final static String TYPE_NAME = "PostalCodeType"; |
338 | 1 | final static String[] HASH_CODE_EQUALS_EXCLUDE = {CoreConstants.CommonElements.FUTURE_ELEMENTS}; |
339 | |
} |
340 | |
|
341 | |
|
342 | |
|
343 | |
|
344 | |
|
345 | 0 | static class Elements { |
346 | |
final static String CODE = "code"; |
347 | |
final static String CITY_NAME = "cityName"; |
348 | |
final static String COUNTRY_CODE = "countryCode"; |
349 | |
final static String STATE_CODE = "stateCode"; |
350 | |
final static String COUNTY_CODE = "countyCode"; |
351 | |
final static String ACTIVE = "active"; |
352 | |
} |
353 | |
} |