@@ -132,25 +132,30 @@ public Address checkStreetName(Address a, ArrayList<String> streetList, Model m)
132132 return newAdd ;
133133 }
134134
135- public void findSuggestedAddresses (String inputText )
135+ public void findSuggestedAddresses (String inputText ) //TODO: this method is not workin corectly yet!!
136136 {
137137 final String regex = "(?<street>([0-9.]{1,3})?[a-zA-ZåæøÅÆØ. ]+)?\\ s*(?<house>\\ d{1,3}[A-Z]?)?\\ s*[,]*\\ s*(?<floor>(st|k(\\ d{1,2})?|[1-9]{1,2}))?\\ s*[,]*\\ s*(?<side>(tv|th|mf|[1-9]{1,2}))?\\ s*[,]*\\ s*(?<postcode>\\ d{4})?\\ s*(?<city>[a-zA-ZåæøÅÆØ., ]+)?" ;
138138 Pattern pattern = Pattern .compile (regex );
139139 Matcher matcher = pattern .matcher (inputText );
140140 StringBuilder sb = new StringBuilder ();
141141 int counter = 0 ;
142142
143-
144-
145143 if (matcher .matches ())
146144 {
147145 if (matcher .group ("street" )!=null )
148146 {
149-
150147 try (Stream <String > streetStream = Files .lines (Paths .get ("src//externals//streetnames.txt" )).filter (s -> s .toLowerCase ().contains (matcher .group ("street" ).toLowerCase ()))) {
151- sb .append (streetStream .filter (s -> s .contains (matcher .group ("street" ))));
152- setChanged ();
153- notifyObservers (sb .toString ());
148+
149+ streetStream .forEach (street ->{
150+ if (inputText .length ()>3 )
151+ {
152+
153+ sb .append (street );
154+ setChanged ();
155+ notifyObservers (sb .toString ());
156+ }
157+ });
158+
154159 } catch (IOException e ) {
155160 e .printStackTrace ();
156161 }
@@ -172,12 +177,12 @@ public void findSuggestedAddresses(String inputText)
172177 }
173178 if (matcher .group ("postcode" )!=null )
174179 {
175- checkPostCity (matcher .group ("postcode" ), sb , matcher );
180+ checkPostCity (matcher .group ("postcode" ), sb );
176181 counter ++;
177182 }
178183 if (matcher .group ("city" )!=null )
179184 {
180- checkPostCity (matcher .group ("city" ), sb , matcher );
185+ checkPostCity (matcher .group ("city" ), sb );
181186 counter ++;
182187
183188 }
@@ -189,16 +194,17 @@ public void findSuggestedAddresses(String inputText)
189194 }
190195
191196 }
192- public void checkPostCity (String input , StringBuilder sb , Matcher matcher )
197+ public void checkPostCity (String input , StringBuilder sb )
193198 {
194199 try (Stream <String > postCityStream = Files .lines (Paths .get ("src//externals//postnumre.txt" )).filter (s -> s .toLowerCase ().contains (input .toLowerCase ())))
195200 {
196201 postCityStream .forEach (e ->{
197202 sb .append (e .toString ());
203+ setChanged ();
204+ notifyObservers (sb .toString ());
198205 });
199206
200- setChanged ();
201- notifyObservers (sb .toString ());
207+
202208 }
203209 catch (IOException e )
204210 {
0 commit comments