Skip to content

Commit 9f72b06

Browse files
committed
Vers. 1.1
1 parent e20e965 commit 9f72b06

File tree

2 files changed

+19
-14
lines changed

2 files changed

+19
-14
lines changed

src/Model/Reader.java

Lines changed: 18 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -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
{

src/View/View.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,6 @@ public View(Model m, Reader r)
5555
centerpane.add(scrollPane);
5656
scrollPane.setPreferredSize(new Dimension(500,400));
5757

58-
5958
window.setLayout(new BorderLayout());
6059
window.add(northpanel, BorderLayout.NORTH);
6160
window.add(centerpane, BorderLayout.CENTER);
@@ -114,7 +113,7 @@ public void setSuggestions()
114113
@Override
115114
public void update(Observable o, Object arg)
116115
{
117-
modelSuggestion.addElement((String) arg+"\n\n");
116+
modelSuggestion.addElement((String) arg);
118117
}
119118

120119
}

0 commit comments

Comments
 (0)