1 package nl.mineleni.openls.databinding.openls;
2
3 import java.util.HashMap;
4 import java.util.Map;
5 import java.util.Vector;
6
7 import nl.mineleni.openls.XmlNamespaceConstants;
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43 public class Address implements XmlNamespaceConstants {
44
45
46
47 private static final long serialVersionUID = -4508692290538906979L;
48
49
50 private String countryCode;
51
52
53 private StreetAddress streetAddress;
54
55
56 private PostalCode postalCode;
57
58
59 private final Vector<Place> place = new Vector<>();
60
61
62 private final Map<String, String> placeMap = new HashMap<>();
63
64
65 private boolean hasCountryCode;
66
67
68 private boolean hasStreetAddress;
69
70
71 private boolean hasPostalCode;
72
73
74
75
76 public Address() {
77 this.hasCountryCode = false;
78 this.hasStreetAddress = false;
79 this.hasPostalCode = false;
80 }
81
82
83
84
85
86
87
88
89
90
91
92 public Address(final String countryCode, final StreetAddress streetAddress,
93 final PostalCode postalCode) {
94 this.hasCountryCode = true;
95 this.countryCode = countryCode;
96 this.hasStreetAddress = true;
97 this.streetAddress = streetAddress;
98 this.hasPostalCode = true;
99 this.postalCode = postalCode;
100 }
101
102
103
104
105
106
107
108 public void setCountryCode(final String countryCode) {
109 this.hasCountryCode = true;
110 this.countryCode = countryCode;
111 }
112
113
114
115
116
117
118 public String getCountryCode() {
119 return this.countryCode;
120 }
121
122
123
124
125
126
127 public boolean hasCountryCode() {
128 return this.hasCountryCode;
129 }
130
131
132
133
134
135
136
137 public void setStreetAddress(final StreetAddress streetAddress) {
138 this.hasStreetAddress = true;
139 this.streetAddress = streetAddress;
140 }
141
142
143
144
145
146
147 public StreetAddress getStreetAddress() {
148 return this.streetAddress;
149 }
150
151
152
153
154
155
156 public boolean hasStreetAddress() {
157 return this.hasStreetAddress;
158 }
159
160
161
162
163
164
165
166 public void setPostalCode(final PostalCode postalCode) {
167 this.hasPostalCode = true;
168 this.postalCode = postalCode;
169 }
170
171
172
173
174
175
176 public PostalCode getPostalCode() {
177 return this.postalCode;
178 }
179
180
181
182
183
184
185 public boolean hasPostalCode() {
186 return this.hasPostalCode;
187 }
188
189
190
191
192
193
194
195 public void addPlace(final Place val) {
196 this.place.add(val);
197 if (!val.getType().equals("")) {
198 this.placeMap.put(val.getType(), val.getPlace());
199 }
200 }
201
202
203
204
205
206
207
208
209 public Place getPlaceAt(final int i) {
210 return this.place.get(i);
211 }
212
213
214
215
216
217
218 public int getPlaceSize() {
219 return this.place.size();
220 }
221
222
223
224
225
226
227
228
229 public String getPlaceByType(final String type) {
230 return this.placeMap.get(type);
231 }
232
233
234
235
236
237
238
239
240 public boolean hasPlaceType(final String type) {
241 return (this.placeMap.get(type) != null);
242 }
243
244
245
246
247
248
249 @Override
250 public String toXML() {
251 final StringBuilder sb = new StringBuilder("<"
252 + XmlNamespaceConstants.OPENLS_NAMESPACE_PREFIX + ":Address");
253 if (this.hasCountryCode()) {
254 sb.append(" countryCode=\"" + this.getCountryCode() + "\"");
255 }
256 sb.append(">");
257 if (this.hasStreetAddress()) {
258 sb.append(this.streetAddress.toXML());
259 }
260 for (final Place pla : this.place) {
261 sb.append(pla.toXML());
262 }
263 if (this.hasPostalCode()) {
264 sb.append(this.postalCode.toXML());
265 }
266 sb.append("</" + XmlNamespaceConstants.OPENLS_NAMESPACE_PREFIX
267 + ":Address>");
268 return sb.toString();
269 }
270 }