From 9db8247e142c88e3637b49e2f7b1cfd1f8d66f44 Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Sun, 9 Jun 2024 15:33:13 +0200 Subject: [PATCH] search method implemented for a max of 200 hits --- .../java/de/hs_mannheim/domain/System.java | 22 ++++++++++++++++++- 1 file changed, 21 insertions(+), 1 deletion(-) diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index ec59eee..a1351c9 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -1,16 +1,22 @@ package de.hs_mannheim.domain; +import java.io.BufferedReader; +import java.io.InputStream; +import java.io.InputStreamReader; import java.net.URI; import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; +import java.nio.charset.StandardCharsets; import java.util.ArrayList; import java.util.HashSet; import java.util.TreeSet; import org.json.JSONObject; +import de.hs_mannheim.ui.Main; + public class System { private User current_user = new User(); @@ -45,7 +51,21 @@ public class System { } public ArrayList search(String hometown_or_zip){ - return new ArrayList(); + + TreeSet zip_set = new TreeSet<>(); + + try (InputStream inputStream = Main.class.getResourceAsStream("/zip.csv"); + BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { + + String line; + while ((line = reader.readLine()) != null) { + if(line.contains("hometown_or_zip")&&zip_set.size()<200) + zip_set.add(line); + } + + } catch (Exception e) {} + + return new ArrayList<>(zip_set); } public ArrayList random_destinations(){