1 |
torben |
2267 |
package dk.daoas.daoadresseservice;
|
2 |
|
|
|
3 |
|
|
import org.apache.commons.lang3.StringUtils;
|
4 |
|
|
import org.apache.commons.lang3.text.WordUtils;
|
5 |
|
|
|
6 |
|
|
public class AddressUtils {
|
7 |
|
|
|
8 |
|
|
public static class SplitResult {
|
9 |
|
|
public String vej = "";
|
10 |
|
|
public String husnr = "";
|
11 |
|
|
public String litra = "";
|
12 |
|
|
public String etage = "";
|
13 |
|
|
public String lejlighed = "";
|
14 |
|
|
public String resten = "";
|
15 |
torben |
2386 |
|
16 |
|
|
@Override
|
17 |
|
|
public String toString() {
|
18 |
|
|
return vej + " / " + husnr + " / " + litra;
|
19 |
|
|
}
|
20 |
torben |
2267 |
}
|
21 |
|
|
|
22 |
|
|
public static String vaskVejnavn(String indVejnavn) {
|
23 |
|
|
String out = indVejnavn.toLowerCase();
|
24 |
|
|
out = out.replace(" ", "");
|
25 |
|
|
out = out.replace(".", "");
|
26 |
|
|
out = out.replace(",", "");
|
27 |
|
|
out = out.replace("-", "");
|
28 |
|
|
out = out.replace("/", "");
|
29 |
|
|
out = out.replace("\\", "");
|
30 |
|
|
out = out.replace("'", "");
|
31 |
torben |
2382 |
out = out.replace(";", "");
|
32 |
|
|
out = out.replace(":", "");
|
33 |
torben |
2386 |
out = out.replace("´", "");
|
34 |
torben |
2267 |
|
35 |
torben |
2386 |
|
36 |
torben |
2267 |
return out;
|
37 |
|
|
}
|
38 |
|
|
|
39 |
torben |
2276 |
public static String injectIntoBk(String bkrute, String injected) {
|
40 |
|
|
String parts[] = bkrute.split("/");
|
41 |
torben |
2283 |
|
42 |
|
|
if (parts.length != 4) {
|
43 |
|
|
System.out.println(">BK " + bkrute);
|
44 |
|
|
return bkrute;
|
45 |
|
|
}
|
46 |
|
|
|
47 |
torben |
2276 |
return parts[0] + "/" + parts[1] + "/" + parts[2] + "/" + injected + parts[3];
|
48 |
|
|
}
|
49 |
|
|
|
50 |
torben |
2267 |
|
51 |
|
|
/*
|
52 |
|
|
* Er en 1-1 port af SplitAdresse() fra funcSplitAdresse.php
|
53 |
|
|
*/
|
54 |
|
|
public static SplitResult splitAdresse(String indAdresse) {
|
55 |
|
|
indAdresse = indAdresse.trim();
|
56 |
|
|
|
57 |
|
|
SplitResult result = new SplitResult();
|
58 |
|
|
|
59 |
|
|
|
60 |
|
|
int i=0;
|
61 |
|
|
int len = indAdresse.length();
|
62 |
|
|
StringBuilder delStreng = new StringBuilder();
|
63 |
|
|
|
64 |
|
|
// ignorer blanke og komma og punktum
|
65 |
|
|
while (i<len && (indAdresse.charAt(i) == '.' || indAdresse.charAt(i) == ',' || indAdresse.charAt(i) == ' ') ) {
|
66 |
|
|
i++;
|
67 |
|
|
}
|
68 |
|
|
|
69 |
|
|
|
70 |
|
|
// alle karakterer indtil det første tal er vejnavn
|
71 |
|
|
while ((i < len) && Character.isDigit(indAdresse.charAt(i))==false ) {
|
72 |
|
|
delStreng.append( indAdresse.charAt(i) );
|
73 |
|
|
i++;
|
74 |
|
|
}
|
75 |
|
|
result.vej = WordUtils.capitalize( delStreng.toString().trim() );
|
76 |
|
|
|
77 |
|
|
|
78 |
|
|
|
79 |
|
|
// første tal er husnummer
|
80 |
|
|
delStreng = new StringBuilder();
|
81 |
|
|
while ((i < len) && Character.isDigit(indAdresse.charAt(i))==true ) {
|
82 |
|
|
delStreng.append( indAdresse.charAt(i) );
|
83 |
|
|
i++;
|
84 |
|
|
}
|
85 |
|
|
result.husnr = delStreng.toString();
|
86 |
|
|
|
87 |
|
|
// ignorer blanke og komma og punktum
|
88 |
|
|
while (i<len && (indAdresse.charAt(i) == '.' || indAdresse.charAt(i) == ',' || indAdresse.charAt(i) == ' ') ) {
|
89 |
|
|
i++;
|
90 |
|
|
}
|
91 |
|
|
|
92 |
|
|
/*
|
93 |
|
|
// hvis næste delstreng er et enkelt bogstav så er det husbogstavet
|
94 |
|
|
delStreng = new StringBuilder();
|
95 |
|
|
while (i<len && Character.isDigit(indAdresse.charAt(i))==false && indAdresse.charAt(i) == '.' && indAdresse.charAt(i) != ',' && indAdresse.charAt(i) != ' ' ) {
|
96 |
|
|
delStreng.append( indAdresse.charAt(i) );
|
97 |
|
|
i++;
|
98 |
|
|
}
|
99 |
|
|
|
100 |
|
|
System.out.println(indAdresse + " >" + delStreng + "< " +i);
|
101 |
|
|
|
102 |
|
|
if (delStreng.length() == 1) {
|
103 |
|
|
|
104 |
|
|
result.litra = delStreng.toString().toUpperCase();
|
105 |
|
|
if ( !Character.isAlphabetic(result.litra.charAt(0))) {
|
106 |
|
|
result.litra = ""; //$HusBogstav må KUN være A-Z
|
107 |
|
|
}
|
108 |
|
|
delStreng = new StringBuilder();
|
109 |
|
|
|
110 |
|
|
// ignorer blanke og komma og punktum
|
111 |
|
|
while (i<len && (indAdresse.charAt(i) == '.' || indAdresse.charAt(i) == ',' || indAdresse.charAt(i) == ' ') ) {
|
112 |
|
|
i++;
|
113 |
|
|
}
|
114 |
|
|
}
|
115 |
|
|
*/
|
116 |
|
|
|
117 |
|
|
if (i>=len) //THN tilføjelse
|
118 |
|
|
return result;
|
119 |
|
|
|
120 |
torben |
2273 |
if (Character.isAlphabetic(indAdresse.charAt(i) )) {
|
121 |
|
|
if ( (i+1 == len ||
|
122 |
|
|
(Character.isAlphabetic(indAdresse.charAt(i+1)) == false && indAdresse.charAt(i+1) != '.')
|
123 |
|
|
)
|
124 |
torben |
2267 |
) {
|
125 |
torben |
2273 |
result.litra = "" + indAdresse.charAt(i);
|
126 |
|
|
result.litra = result.litra.toUpperCase();
|
127 |
|
|
i++;
|
128 |
|
|
}
|
129 |
torben |
2267 |
}
|
130 |
|
|
|
131 |
|
|
|
132 |
|
|
|
133 |
|
|
|
134 |
|
|
// første tal er etage (eller evt. st er stuen)
|
135 |
|
|
if (delStreng.toString().toLowerCase().equals("st")) {
|
136 |
|
|
result.etage = delStreng.toString().toLowerCase();
|
137 |
|
|
}
|
138 |
|
|
else {
|
139 |
|
|
delStreng = new StringBuilder();
|
140 |
|
|
String nextTwo = StringUtils.substring(indAdresse, i, i+2).toLowerCase();
|
141 |
|
|
if ( nextTwo.equals("st") ) {
|
142 |
|
|
result.etage = nextTwo;
|
143 |
|
|
i += nextTwo.length();
|
144 |
|
|
}
|
145 |
|
|
else {
|
146 |
|
|
while ((i < len) && Character.isDigit(indAdresse.charAt(i))==true ) {
|
147 |
|
|
delStreng.append( indAdresse.charAt(i) );
|
148 |
|
|
i++;
|
149 |
|
|
}
|
150 |
|
|
result.etage = delStreng.toString();
|
151 |
|
|
}
|
152 |
|
|
}
|
153 |
|
|
|
154 |
|
|
|
155 |
|
|
// Hvis vi fandt en etage angivelse skal vi også kigge efter lejlighed/side
|
156 |
|
|
if (result.etage.length() > 0 ) {
|
157 |
|
|
|
158 |
|
|
// ignorer blanke og komma og punktum
|
159 |
|
|
while (i<len && (indAdresse.charAt(i) == '.' || indAdresse.charAt(i) == ',' || indAdresse.charAt(i) == ' ') ) {
|
160 |
|
|
i++;
|
161 |
|
|
}
|
162 |
|
|
|
163 |
|
|
|
164 |
|
|
String next = StringUtils.substring(indAdresse, i, i+3).toLowerCase();
|
165 |
|
|
// Ignorer hvis næste info er 'sal'
|
166 |
|
|
if (next.equals("sal")) {
|
167 |
|
|
i += 3;
|
168 |
|
|
|
169 |
|
|
// ignorer blanke og komma og punktum
|
170 |
|
|
while (i<len && (indAdresse.charAt(i) == '.' || indAdresse.charAt(i) == ',' || indAdresse.charAt(i) == ' ') ) {
|
171 |
|
|
i++;
|
172 |
|
|
}
|
173 |
|
|
}
|
174 |
|
|
|
175 |
|
|
next = StringUtils.substring(indAdresse, i, i+3).toLowerCase();
|
176 |
|
|
// Ignorer hvis næste info er 'dør'
|
177 |
|
|
if (next.equals("dør")) {
|
178 |
|
|
i += 3;
|
179 |
|
|
|
180 |
|
|
// ignorer blanke og komma og punktum
|
181 |
|
|
while (i<len && (indAdresse.charAt(i) == '.' || indAdresse.charAt(i) == ',' || indAdresse.charAt(i) == ' ') ) {
|
182 |
|
|
i++;
|
183 |
|
|
}
|
184 |
|
|
}
|
185 |
|
|
|
186 |
|
|
// Ignorer hvis næste info er 'lejlighed' eller 'lejl.' eller 'Lej'
|
187 |
|
|
next = StringUtils.substring(indAdresse, i, i+9).toLowerCase();
|
188 |
|
|
if (next.equals("lejlighed") ) {
|
189 |
|
|
i += 9;
|
190 |
|
|
}
|
191 |
|
|
next = StringUtils.substring(indAdresse, i, i+4).toLowerCase();
|
192 |
|
|
if (next.equals("lejl") ) {
|
193 |
|
|
i += 4;
|
194 |
|
|
}
|
195 |
|
|
next = StringUtils.substring(indAdresse, i, i+3).toLowerCase();
|
196 |
|
|
if (next.equals("lej") ) {
|
197 |
|
|
i += 3;
|
198 |
|
|
}
|
199 |
|
|
|
200 |
|
|
// ignorer blanke og komma og punktum
|
201 |
|
|
while (i<len && (indAdresse.charAt(i) == '.' || indAdresse.charAt(i) == ',' || indAdresse.charAt(i) == ' ') ) {
|
202 |
|
|
i++;
|
203 |
|
|
}
|
204 |
|
|
|
205 |
|
|
// alle karakterer indtil det første blanke er lejlighed/side
|
206 |
|
|
delStreng = new StringBuilder();
|
207 |
|
|
while (i<len && indAdresse.charAt(i) != ' ') {
|
208 |
|
|
delStreng.append( indAdresse.charAt(i) );
|
209 |
|
|
i++;
|
210 |
|
|
}
|
211 |
|
|
result.lejlighed = delStreng.toString().toLowerCase();
|
212 |
|
|
result.lejlighed = result.lejlighed.replace(".", "");
|
213 |
|
|
}
|
214 |
|
|
|
215 |
|
|
// saml resten op (kan gøres smartere med en substr)
|
216 |
torben |
2273 |
result.resten = indAdresse.substring(i).trim();
|
217 |
torben |
2267 |
|
218 |
|
|
return result;
|
219 |
|
|
}
|
220 |
|
|
|
221 |
|
|
}
|
222 |
|
|
|
223 |
|
|
|