diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index 8249626..128203d 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -1,15 +1,23 @@ 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; 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(); @@ -43,12 +51,31 @@ public class System { return true; } - public TreeSet search(String hometown_or_zip){ - return new TreeSet(); + public ArrayList search(String hometown_or_zip){ + + TreeSet zip_set = new TreeSet<>(); + + 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){ + line = line.replace("\"", ""); + zip_set.add(line); + } + } + } catch (IOException e) {} + + return new ArrayList<>(zip_set); } - public TreeSet random_destinations(){ - return new TreeSet(); + public ArrayList random_destinations_car(){ + return new ArrayList(); + } + + public ArrayList random_destinations_bike(){ + return new ArrayList(); } public String[] destination_details(String destination_zip){ diff --git a/src/main/java/de/hs_mannheim/facade/Application.java b/src/main/java/de/hs_mannheim/facade/Application.java index 14d3c20..8a87955 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,16 @@ 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_car(){ + return new ArrayList(); + } + + public ArrayList random_destinations_bike(){ + return new ArrayList(); } public String[] destination_details(String destination_zip){ 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]); + + } + }