1
2
3
4 package de.powerstat.validation.values;
5
6
7 import java.util.Arrays;
8 import java.util.Objects;
9
10
11
12
13
14
15
16
17
18 public final class AddressWithWGS84Position extends Address
19 {
20
21
22
23
24
25
26
27
28 private final WGS84Position position;
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51 private AddressWithWGS84Position(final Country country, final PostalCode postalCode, final City city, final Province province, final District district, final Street street, final BuildingNr buildingNr, final BuildingName buildingName, final SubBuilding subBuilding, final PoBoxNumber poBoxNumber, final Department department, final Neighbourhood neighbourhood, final Block block, final BFPONumber bFPONumber, final Lines lines, final WGS84Position position)
52 {
53 super(country, postalCode, city, province, district, street, buildingNr, buildingName, subBuilding, poBoxNumber, department, neighbourhood, block, bFPONumber, lines);
54 Objects.requireNonNull(position, "position");
55 this.position = position;
56 }
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80 public static AddressWithWGS84Position of(final Country country, final PostalCode postalCode, final City city, final Province province, final District district, final Street street, final BuildingNr buildingNr, final BuildingName buildingName, final SubBuilding subBuilding, final PoBoxNumber poBoxNumber, final Department department, final Neighbourhood neighbourhood, final Block block, final BFPONumber bFPONumber, final Lines lines, final WGS84Position position)
81 {
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96 return new AddressWithWGS84Position(country, postalCode, city, province, district, street, buildingNr, buildingName, subBuilding, poBoxNumber, department, neighbourhood, block, bFPONumber, lines, position);
97 }
98
99
100
101
102
103
104
105
106 public static AddressWithWGS84Position of(final String value)
107 {
108 String[] values = value.split(",");
109 if ((values.length < 1) || (values.length > 16))
110 {
111 throw new IllegalArgumentException("value not in expected format: " + values.length);
112 }
113 if (values.length < 16)
114 {
115 values = Arrays.copyOf(values, 16);
116 for (int i = 1; i < 16; ++i)
117 {
118 if (values[i] == null)
119 {
120 values[i] = "";
121 }
122 }
123 }
124 final var country = Country.of(values[0]);
125 final PostalCode postalCode = values[1].isEmpty() ? null : PostalCode.of(values[1]);
126 final City city = values[2].isEmpty() ? null : City.of(values[2]);
127 final Province province = values[3].isEmpty() ? null : Province.of(values[3]);
128 final District district = values[4].isEmpty() ? null : District.of(values[4]);
129 final Street street = values[5].isEmpty() ? null : Street.of(values[5]);
130 final BuildingNr buildingNr = values[6].isEmpty() ? null : BuildingNr.of(values[6]);
131 final BuildingName buildingName = values[7].isEmpty() ? null : BuildingName.of(values[7]);
132 final SubBuilding subBuilding = values[8].isEmpty() ? null : SubBuilding.of(values[8]);
133 final PoBoxNumber poBoxNumber = values[9].isEmpty() ? null : PoBoxNumber.of(values[9]);
134 final Department department = values[10].isEmpty() ? null : Department.of(values[10]);
135 final Neighbourhood neighbourhood = values[11].isEmpty() ? null : Neighbourhood.of(values[11]);
136 final Block block = values[12].isEmpty() ? null : Block.of(values[12]);
137 final BFPONumber bFPONumber = values[13].isEmpty() ? null : BFPONumber.of(values[13]);
138 final Lines lines = values[14].isEmpty() ? null : Lines.of(values[14]);
139 final WGS84Position position = values[15].isEmpty() ? null : WGS84Position.of(values[15]);
140 return of(country, postalCode, city, province, district, street, buildingNr, buildingName, subBuilding, poBoxNumber, department, neighbourhood, block, bFPONumber, lines, position);
141 }
142
143
144
145
146
147
148
149 public WGS84Position getPosition()
150 {
151 return this.position;
152 }
153
154
155
156
157
158
159
160 @Override
161 public String stringValue()
162 {
163 return super.stringValue() + this.position.stringValue();
164 }
165
166
167
168
169
170
171
172
173 @Override
174 public int hashCode()
175 {
176 return Objects.hash(super.hashCode(), this.position);
177 }
178
179
180
181
182
183
184
185
186
187 @Override
188 public boolean equals(final Object obj)
189 {
190 if (this == obj)
191 {
192 return true;
193 }
194
195 if (!(obj instanceof AddressWithWGS84Position))
196 {
197 return false;
198 }
199 final AddressWithWGS84Position other = (AddressWithWGS84Position)obj;
200 boolean result = this.position.equals(other.position);
201 if (result)
202 {
203 result = super.equals(other);
204 }
205 return result;
206 }
207
208
209
210
211
212
213
214
215
216
217
218
219 @SuppressWarnings({"checkstyle:NoWhitespaceBefore", "checkstyle:SeparatorWrap"})
220 @Override
221 public String toString()
222 {
223 final var builder = new StringBuilder(182);
224 builder.append("AddressWithWGS84Position[position=").append(this.position)
225 .append(", ").append(super.toString())
226 .append(']');
227 return builder.toString();
228 }
229
230 }