Merge branch 'get_destinations_methods'

distance_method
Selim Eser 2024-06-09 16:14:35 +02:00
commit c43fe4196c
3 changed files with 54 additions and 8 deletions

View File

@ -1,15 +1,23 @@
package de.hs_mannheim.domain; 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.URI;
import java.net.http.HttpClient; import java.net.http.HttpClient;
import java.net.http.HttpRequest; import java.net.http.HttpRequest;
import java.net.http.HttpResponse; import java.net.http.HttpResponse;
import java.net.http.HttpResponse.BodyHandlers; import java.net.http.HttpResponse.BodyHandlers;
import java.nio.charset.StandardCharsets;
import java.util.ArrayList;
import java.util.HashSet; import java.util.HashSet;
import java.util.TreeSet; import java.util.TreeSet;
import org.json.JSONObject; import org.json.JSONObject;
import de.hs_mannheim.ui.Main;
public class System { public class System {
private User current_user = new User(); private User current_user = new User();
@ -43,12 +51,31 @@ public class System {
return true; return true;
} }
public TreeSet<String> search(String hometown_or_zip){ public ArrayList<String> search(String hometown_or_zip){
return new TreeSet<String>();
TreeSet<String> 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<String> random_destinations(){ public ArrayList<String> random_destinations_car(){
return new TreeSet<String>(); return new ArrayList<String>();
}
public ArrayList<String> random_destinations_bike(){
return new ArrayList<String>();
} }
public String[] destination_details(String destination_zip){ public String[] destination_details(String destination_zip){

View File

@ -1,5 +1,6 @@
package de.hs_mannheim.facade; package de.hs_mannheim.facade;
import java.util.ArrayList;
import java.util.TreeSet; import java.util.TreeSet;
import de.hs_mannheim.domain.System; import de.hs_mannheim.domain.System;
@ -28,12 +29,16 @@ public class Application {
return true; return true;
} }
public TreeSet<String> search(String hometown_or_zip){ public ArrayList<String> search(String hometown_or_zip){
return new TreeSet<String>(); return new ArrayList<String>();
} }
public TreeSet<String> random_destinations(){ public ArrayList<String> random_destinations_car(){
return new TreeSet<String>(); return new ArrayList<String>();
}
public ArrayList<String> random_destinations_bike(){
return new ArrayList<String>();
} }
public String[] destination_details(String destination_zip){ public String[] destination_details(String destination_zip){

View File

@ -3,6 +3,8 @@ package de.hs_mannheim.domain;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertNotEquals;
import java.util.ArrayList;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
public class SystemTest { public class SystemTest {
@ -25,4 +27,16 @@ public class SystemTest {
assertNotEquals("Es ist ein Fehler aufgetreten!",current_system.current_weather()); assertNotEquals("Es ist ein Fehler aufgetreten!",current_system.current_weather());
} }
@Test
public void search(){
System current_system = new System("35a75437476f12302f72e55d368485db");
ArrayList<String> list = current_system.search("Mannheim");
assertEquals("68159", list.get(0).split(";")[0]);
assertEquals("68167", list.get(4).split(";")[0]);
}
} }