3 |
import org.apache.commons.lang3.StringUtils; |
import org.apache.commons.lang3.StringUtils; |
4 |
import org.apache.commons.lang3.text.WordUtils; |
import org.apache.commons.lang3.text.WordUtils; |
5 |
|
|
6 |
|
import dk.daoas.daoadresseservice.beans.Address; |
7 |
|
|
8 |
public class AddressUtils { |
public class AddressUtils { |
9 |
|
|
10 |
public static class SplitResult { |
public static class SplitResult { |
14 |
public String etage = ""; |
public String etage = ""; |
15 |
public String lejlighed = ""; |
public String lejlighed = ""; |
16 |
public String resten = ""; |
public String resten = ""; |
17 |
|
|
18 |
|
@Override |
19 |
|
public String toString() { |
20 |
|
return vej + " / " + husnr + " / " + litra; |
21 |
|
} |
22 |
|
} |
23 |
|
|
24 |
|
public static char fjernAccentTegn(char c) { |
25 |
|
switch (c) { |
26 |
|
case 'é': |
27 |
|
return 'e'; |
28 |
|
case 'è': |
29 |
|
return 'e'; |
30 |
|
|
31 |
|
case 'û': |
32 |
|
return 'u'; |
33 |
|
case 'ü': |
34 |
|
return 'u'; |
35 |
|
|
36 |
|
case 'ö': |
37 |
|
return 'ø'; |
38 |
|
case 'ô': |
39 |
|
return 'o'; |
40 |
|
|
41 |
|
case 'ä': |
42 |
|
return 'æ'; |
43 |
|
case 'â': |
44 |
|
return 'a'; |
45 |
|
|
46 |
|
case 'ñ': |
47 |
|
return 'n'; |
48 |
|
|
49 |
|
default: |
50 |
|
return c; |
51 |
|
} |
52 |
} |
} |
53 |
|
|
54 |
public static String vaskVejnavn(String indVejnavn) { |
public static String vaskVejnavn(String indVejnavn) { |
55 |
String out = indVejnavn.toLowerCase(); |
StringBuilder sb = new StringBuilder(); |
56 |
out = out.replace(" ", ""); |
char chars[] = indVejnavn.toCharArray(); |
|
out = out.replace(".", ""); |
|
|
out = out.replace(",", ""); |
|
|
out = out.replace("-", ""); |
|
|
out = out.replace("/", ""); |
|
|
out = out.replace("\\", ""); |
|
|
out = out.replace("'", ""); |
|
57 |
|
|
58 |
return out; |
for (char c: chars) { |
59 |
|
if ( Character.isAlphabetic(c)) { |
60 |
|
c = Character.toLowerCase(c); |
61 |
|
c = fjernAccentTegn(c); |
62 |
|
|
63 |
|
sb.append( c ); |
64 |
|
} else if ( Character.isDigit(c)) { |
65 |
|
sb.append(c); |
66 |
|
} |
67 |
|
|
68 |
|
} |
69 |
|
|
70 |
|
return sb.toString(); |
71 |
} |
} |
72 |
|
|
73 |
public static String injectIntoBk(String bkrute, String injected) { |
public static String injectIntoBk(String bkrute, String injected) { |
74 |
|
if (bkrute == null) |
75 |
|
return null; |
76 |
|
|
77 |
String parts[] = bkrute.split("/"); |
String parts[] = bkrute.split("/"); |
78 |
|
|
79 |
if (parts.length != 4) { |
if (parts.length != 4) { |
|
System.out.println(">BK " + bkrute); |
|
80 |
return bkrute; |
return bkrute; |
81 |
} |
} |
82 |
|
|
101 |
while (i<len && (indAdresse.charAt(i) == '.' || indAdresse.charAt(i) == ',' || indAdresse.charAt(i) == ' ') ) { |
while (i<len && (indAdresse.charAt(i) == '.' || indAdresse.charAt(i) == ',' || indAdresse.charAt(i) == ' ') ) { |
102 |
i++; |
i++; |
103 |
} |
} |
104 |
|
|
105 |
|
|
106 |
|
// alle tegn frem til og med første bogstav er også en del af vejnavn |
107 |
|
while ((i < len) && Character.isAlphabetic(indAdresse.charAt(i))==false ) { |
108 |
|
delStreng.append( indAdresse.charAt(i) ); |
109 |
|
i++; |
110 |
|
} |
111 |
|
|
112 |
|
|
113 |
// alle karakterer indtil det første tal er vejnavn |
// alle karakterer indtil det første tal er vejnavn |
115 |
delStreng.append( indAdresse.charAt(i) ); |
delStreng.append( indAdresse.charAt(i) ); |
116 |
i++; |
i++; |
117 |
} |
} |
118 |
result.vej = WordUtils.capitalize( delStreng.toString().trim() ); |
|
119 |
|
|
120 |
|
result.vej = delStreng.toString().toLowerCase().trim(); |
121 |
|
if ( result.vej.endsWith(".") || result.vej.endsWith(",")) { |
122 |
|
result.vej = result.vej.substring(0, result.vej.length() - 1); |
123 |
|
result.vej = result.vej.trim(); |
124 |
|
} |
125 |
|
|
126 |
|
//special case - hvis strengen ender med ' nr' skal ' nr' fjernes |
127 |
|
if ( result.vej.endsWith(" nr")) { |
128 |
|
result.vej = result.vej.substring(0, result.vej.length() - 3); |
129 |
|
} |
130 |
|
|
131 |
|
result.vej = WordUtils.capitalize( result.vej.trim() ); |
132 |
|
|
133 |
|
|
134 |
|
|
173 |
if (i>=len) //THN tilføjelse |
if (i>=len) //THN tilføjelse |
174 |
return result; |
return result; |
175 |
|
|
176 |
if (Character.isAlphabetic(indAdresse.charAt(i) )) { |
if (Character.isAlphabetic(indAdresse.charAt(i) )) { |
177 |
if ( (i+1 == len || |
char current = Character.toUpperCase( indAdresse.charAt(i) ); |
178 |
(Character.isAlphabetic(indAdresse.charAt(i+1)) == false && indAdresse.charAt(i+1) != '.') |
|
179 |
) |
if (current != 'Æ'&& current != 'Ø' && current != 'Å') { |
180 |
) { |
if ( (i+1 == len || |
181 |
result.litra = "" + indAdresse.charAt(i); |
(Character.isAlphabetic(indAdresse.charAt(i+1) ) == false |
182 |
result.litra = result.litra.toUpperCase(); |
/*&& indAdresse.charAt(i+1) != '.'*/ |
183 |
i++; |
|
184 |
|
&& checkCo(indAdresse,i) == false // Fra sortér C/O |
185 |
|
) |
186 |
|
) |
187 |
|
) { |
188 |
|
result.litra = "" + current; |
189 |
|
i++; |
190 |
|
} |
191 |
} |
} |
192 |
} |
} |
193 |
|
|
194 |
|
// ignorer blanke og komma og punktum |
195 |
|
while (i<len && (indAdresse.charAt(i) == '.' || indAdresse.charAt(i) == ',' || indAdresse.charAt(i) == ' ') ) { |
196 |
|
i++; |
197 |
|
} |
198 |
|
|
199 |
|
|
200 |
|
|
201 |
|
|
286 |
return result; |
return result; |
287 |
} |
} |
288 |
|
|
289 |
|
public static boolean checkCo(String addr, int pos) { |
290 |
|
|
291 |
|
if ( StringUtils.substring(addr, pos, pos+3).equalsIgnoreCase("C/O") ) |
292 |
|
return true; |
293 |
|
|
294 |
|
return false; |
295 |
|
|
296 |
|
} |
297 |
|
|
298 |
|
public static void updateDaekningstype(Address a) { |
299 |
|
if (a.rute != null && a.rute.length()> 0) { |
300 |
|
a.daekningsType = DaekningsType.DAEKNING_DIREKTE; |
301 |
|
} else { |
302 |
|
a.daekningsType = DaekningsType.DAEKNING_IKKEDAEKKET; |
303 |
|
} |
304 |
|
} |
305 |
|
|
306 |
} |
} |
307 |
|
|
308 |
|
|