From 1be9d7b4295e052b1abc13b52a580a360d9127e6 Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Sun, 9 Jun 2024 15:17:47 +0200 Subject: [PATCH 1/7] Changed method return to ArrayList --- src/main/java/de/hs_mannheim/domain/System.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index 8249626..ec59eee 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -5,6 +5,7 @@ import java.net.http.HttpClient; import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; +import java.util.ArrayList; import java.util.HashSet; import java.util.TreeSet; @@ -43,12 +44,12 @@ public class System { return true; } - public TreeSet search(String hometown_or_zip){ - return new TreeSet(); + public ArrayList search(String hometown_or_zip){ + return new ArrayList(); } - public TreeSet random_destinations(){ - return new TreeSet(); + public ArrayList random_destinations(){ + return new ArrayList(); } public String[] destination_details(String destination_zip){ From 757e33fc8f1cdba53b4afb0fe0e04e666155c33d Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Sun, 9 Jun 2024 15:19:05 +0200 Subject: [PATCH 2/7] Changed method return to ArrayList in Application.java aswell --- src/main/java/de/hs_mannheim/facade/Application.java | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/src/main/java/de/hs_mannheim/facade/Application.java b/src/main/java/de/hs_mannheim/facade/Application.java index 14d3c20..6db7b10 100644 --- a/src/main/java/de/hs_mannheim/facade/Application.java +++ b/src/main/java/de/hs_mannheim/facade/Application.java @@ -1,5 +1,6 @@ package de.hs_mannheim.facade; +import java.util.ArrayList; import java.util.TreeSet; import de.hs_mannheim.domain.System; @@ -28,12 +29,12 @@ public class Application { return true; } - public TreeSet search(String hometown_or_zip){ - return new TreeSet(); + public ArrayList search(String hometown_or_zip){ + return new ArrayList(); } - public TreeSet random_destinations(){ - return new TreeSet(); + public ArrayList random_destinations(){ + return new ArrayList(); } public String[] destination_details(String destination_zip){ 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 3/7] 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(){ From 671553bd195533de89c7fb36ba6baa5db5dbfebd Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Sun, 9 Jun 2024 15:58:25 +0200 Subject: [PATCH 4/7] Removed unwanted chars from return String of ArrayList --- src/main/java/de/hs_mannheim/domain/System.java | 14 +++++++++----- 1 file changed, 9 insertions(+), 5 deletions(-) diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index a1351c9..93e8c2e 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -1,6 +1,7 @@ package de.hs_mannheim.domain; import java.io.BufferedReader; +import java.io.IOException; import java.io.InputStream; import java.io.InputStreamReader; import java.net.URI; @@ -54,16 +55,19 @@ public class System { TreeSet zip_set = new TreeSet<>(); - try (InputStream inputStream = Main.class.getResourceAsStream("/zip.csv"); - BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream, StandardCharsets.UTF_8))) { + InputStream inputStream = Main.class.getResourceAsStream("/zip.csv"); + try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { String line; while ((line = reader.readLine()) != null) { - if(line.contains("hometown_or_zip")&&zip_set.size()<200) + if(line.contains(hometown_or_zip)&&zip_set.size()<200){ + line = line.replace("\"", ""); zip_set.add(line); + } } - - } catch (Exception e) {} + } catch (IOException e) { + e.printStackTrace(); + } return new ArrayList<>(zip_set); } From 6d96b3ba76e322b703b701f21800a72b09cbb2a7 Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Sun, 9 Jun 2024 16:03:05 +0200 Subject: [PATCH 5/7] search method tests implemented and successfull --- .../java/de/hs_mannheim/domain/SystemTest.java | 14 ++++++++++++++ 1 file changed, 14 insertions(+) diff --git a/src/test/java/de/hs_mannheim/domain/SystemTest.java b/src/test/java/de/hs_mannheim/domain/SystemTest.java index 07714b8..bc8acac 100644 --- a/src/test/java/de/hs_mannheim/domain/SystemTest.java +++ b/src/test/java/de/hs_mannheim/domain/SystemTest.java @@ -3,6 +3,8 @@ package de.hs_mannheim.domain; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals; +import java.util.ArrayList; + import org.junit.jupiter.api.Test; public class SystemTest { @@ -25,4 +27,16 @@ public class SystemTest { assertNotEquals("Es ist ein Fehler aufgetreten!",current_system.current_weather()); } + @Test + public void search(){ + + System current_system = new System("35a75437476f12302f72e55d368485db"); + + ArrayList list = current_system.search("Mannheim"); + + assertEquals("68159", list.get(0).split(";")[0]); + assertEquals("68167", list.get(4).split(";")[0]); + + } + } From ee784a91b20371939f4e77d83fb66931b429c23e Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Sun, 9 Jun 2024 16:06:15 +0200 Subject: [PATCH 6/7] random_destinations method for car and bike splitted --- src/main/java/de/hs_mannheim/domain/System.java | 6 +++++- src/main/java/de/hs_mannheim/facade/Application.java | 6 +++++- 2 files changed, 10 insertions(+), 2 deletions(-) diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index 93e8c2e..436a96c 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -72,7 +72,11 @@ public class System { return new ArrayList<>(zip_set); } - public ArrayList random_destinations(){ + public ArrayList random_destinations_car(){ + return new ArrayList(); + } + + public ArrayList random_destinations_bike(){ return new ArrayList(); } diff --git a/src/main/java/de/hs_mannheim/facade/Application.java b/src/main/java/de/hs_mannheim/facade/Application.java index 6db7b10..8a87955 100644 --- a/src/main/java/de/hs_mannheim/facade/Application.java +++ b/src/main/java/de/hs_mannheim/facade/Application.java @@ -33,7 +33,11 @@ public class Application { return new ArrayList(); } - public ArrayList random_destinations(){ + public ArrayList random_destinations_car(){ + return new ArrayList(); + } + + public ArrayList random_destinations_bike(){ return new ArrayList(); } From 3455d7b1b7592971983be7c779fd7e39e99b9c0d Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Sun, 9 Jun 2024 16:13:20 +0200 Subject: [PATCH 7/7] random_destinations methods require distance methode ... implementing later --- src/main/java/de/hs_mannheim/domain/System.java | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index 436a96c..128203d 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -65,9 +65,7 @@ public class System { zip_set.add(line); } } - } catch (IOException e) { - e.printStackTrace(); - } + } catch (IOException e) {} return new ArrayList<>(zip_set); }