From d5408617e17d8c7c62abba891598de96eec905df Mon Sep 17 00:00:00 2001 From: Selim Eser <2211482@stud.hs-mannheim.de> Date: Tue, 11 Jun 2024 22:11:11 +0200 Subject: [PATCH] Destination.java created in order to calc all destination distances once --- .DS_Store | Bin 0 -> 6148 bytes .../de/hs_mannheim/domain/Destination.java | 22 ++++++++++ .../java/de/hs_mannheim/domain/System.java | 38 ++++++------------ src/main/java/de/hs_mannheim/domain/User.java | 8 ++-- 4 files changed, 39 insertions(+), 29 deletions(-) create mode 100644 .DS_Store create mode 100644 src/main/java/de/hs_mannheim/domain/Destination.java diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..33584f90c2eb03423002dd4a65e7aac253e1829f GIT binary patch literal 6148 zcmeHKOHKnZ41J~*RASR58>F0|5;q7{S+MQ}papd^bgI%;EayfX5uRgHF_0|?AzN~u z6MrUo(&Pg`ru&C0U<_bHRTMQUqQh0!i3bmfQfj>53C(TOE*DLu&|e(Vxu0Q!mNTE= z)BM{7Jxa?pb@En(7BIjwwpiLKk5RAnsKb1_Zrb&VUNVGJ>~PQQ6&|tcSCGpu71#|4 z27-ZLAQ%V+et-czktm~c!)SwnU?3PcGNAiIqAF&`&aiA9Y|0aWsMqKswDr=gImt0Q zc82sQctD*nU}OXqm#3kHILf5w0eXY<*Vi}JJe+w%0RP1HN8ipF(nP-yoq0qp2La#5V-PiiwR XJ9dUzMaN4zF)jjykZ6K|Utr)JY4bL9 literal 0 HcmV?d00001 diff --git a/src/main/java/de/hs_mannheim/domain/Destination.java b/src/main/java/de/hs_mannheim/domain/Destination.java new file mode 100644 index 0000000..23f03a6 --- /dev/null +++ b/src/main/java/de/hs_mannheim/domain/Destination.java @@ -0,0 +1,22 @@ +package de.hs_mannheim.domain; + +public class Destination { + + private String zip; + private double distance_from_user; + + public String getZip() { + return zip; + } + public void setZip(String zip) { + this.zip = zip; + } + public double getDistance_from_user() { + return distance_from_user; + } + public void setDistance_from_user(double distance_from_user) { + this.distance_from_user = distance_from_user; + } + + +} diff --git a/src/main/java/de/hs_mannheim/domain/System.java b/src/main/java/de/hs_mannheim/domain/System.java index 376d237..5b241f8 100644 --- a/src/main/java/de/hs_mannheim/domain/System.java +++ b/src/main/java/de/hs_mannheim/domain/System.java @@ -7,6 +7,7 @@ import java.net.http.HttpRequest; import java.net.http.HttpResponse; import java.net.http.HttpResponse.BodyHandlers; import java.util.ArrayList; +import java.util.HashMap; import java.util.TreeSet; import org.apache.commons.codec.binary.Base64; @@ -17,6 +18,7 @@ public class System { private User current_user = new User(); private ArrayList all_user = new ArrayList<>(); private String api_key; + private HashMap all_destinations = new HashMap(); private ArrayList distances = new ArrayList<>(); public System(String api_key) { @@ -25,7 +27,7 @@ public class System { } public void set_current_user_zip(String zip) { - this.current_user.setZip(Integer.parseInt(zip)); + this.current_user.setZip(zip); } public void set_current_user_car_l_100km(double car_l_100km) { @@ -56,13 +58,6 @@ public class System { return Base64.encodeBase64String(binary_data); } - public static int parseInt(String s) throws NumberFormatException{ - if(s.equals("")) - return 0; - else - return Integer.parseInt(s); - } - public static double parseDouble(String s) throws NumberFormatException { if(s.equals("")) return 0; @@ -81,7 +76,7 @@ public class System { fileString = path.split(";"); fileString[1] = decoding(fileString[1]); this.all_user.add(new User(fileString[0], fileString[1], fileString[2], - Integer.parseInt(fileString[3]), fileString[4], + fileString[3], fileString[4], Double.parseDouble(fileString[5]), Double.parseDouble(fileString[6]), Double.parseDouble(fileString[7]))); @@ -114,16 +109,14 @@ public class System { return false; } - public boolean sign_up_user(String username, String password, String hometown, String zipS, + public boolean sign_up_user(String username, String password, String hometown, String zip, String car_name, String car_l_100kmS, String car_avg_kmhS, String bike_avg_kmhS){ - int zip; double car_l_100km; double car_avg_kmh; double bike_avg_kmh; try{ - zip = parseInt(zipS); car_l_100km = parseDouble(car_l_100kmS); car_avg_kmh = parseDouble(car_avg_kmhS); bike_avg_kmh = parseDouble(bike_avg_kmhS); @@ -131,14 +124,14 @@ public class System { return false; } - if(username.equals("")||password.equals("")||hometown.equals("")||zipS.equals("")) + if(username.equals("")||password.equals("")||hometown.equals("")||zip.equals("")) return false; for(User user: this.all_user) if(user.getUsername().equals(username)) return false; - ArrayList mem = search(zipS); + ArrayList mem = search(zip); boolean bool = false; for (String line: mem) @@ -160,16 +153,14 @@ public class System { return true; } - public boolean change_user_details(String username, String password, String hometown, String zipS, + public boolean change_user_details(String username, String password, String hometown, String zip, String car_name, String car_l_100kmS, String car_avg_kmhS, String bike_avg_kmhS){ - int zip; double car_l_100km; double car_avg_kmh; double bike_avg_kmh; try{ - zip = parseInt(zipS); car_l_100km = parseDouble(car_l_100kmS); car_avg_kmh = parseDouble(car_avg_kmhS); bike_avg_kmh = parseDouble(bike_avg_kmhS); @@ -177,14 +168,14 @@ public class System { return false; } - if(username.equals("")||password.equals("")||hometown.equals("")||zipS.equals("")) + if(username.equals("")||password.equals("")||hometown.equals("")||zip.equals("")) return false; for(User user: this.all_user) if(user.getUsername().equals(username)) return false; - ArrayList mem = search(zipS); + ArrayList mem = search(zip); boolean bool = false; for (String line: mem) @@ -232,9 +223,7 @@ public class System { public String[] getDetails(){ return new String[]{current_user.getUsername(), current_user.getPassword(), - current_user.getHometown(), - current_user.getZip()==0?"":String.valueOf(current_user.getZip()), - current_user.getCar_name(), + current_user.getHometown(), current_user.getZip(), current_user.getCar_name(), current_user.getCar_l_100km()==0?"":String.valueOf(current_user.getCar_l_100km()), current_user.getCar_avg_kmh()==0?"":String.valueOf(current_user.getCar_avg_kmh()), current_user.getBike_avg_kmh()==0?"":String.valueOf(current_user.getBike_avg_kmh())}; @@ -249,10 +238,9 @@ public class System { try (BufferedReader reader = new BufferedReader(new InputStreamReader(inputStream))) { String line; while ((line = reader.readLine()) != null && zip_set.size() < 200) { - if (line.contains(hometown_or_zip)) { - line = line.replace("\"", ""); + line = line.replace("\"", ""); + if (line.split(";")[0].contains(hometown_or_zip)||line.split(";")[1].contains(hometown_or_zip)) zip_set.add(line); - } } } catch (Exception e) { } diff --git a/src/main/java/de/hs_mannheim/domain/User.java b/src/main/java/de/hs_mannheim/domain/User.java index b1f311b..5a6daeb 100644 --- a/src/main/java/de/hs_mannheim/domain/User.java +++ b/src/main/java/de/hs_mannheim/domain/User.java @@ -5,7 +5,7 @@ public class User { private String username = ""; private String password = ""; private String hometown = ""; - private int zip = 0; + private String zip = ""; private String car_name = ""; private double car_l_100km = 0; private double car_avg_kmh = 0; @@ -13,7 +13,7 @@ public class User { public User(){} - public User(String username, String password, String hometown, int zip + public User(String username, String password, String hometown, String zip , String car_name, double car_l_100km, double car_avg_kmh, double bike_avg_kmh){ this.username = username; this.password = password; @@ -49,11 +49,11 @@ public class User { this.hometown = hometown; } - public int getZip() { + public String getZip() { return zip; } - public void setZip(int zip) { + public void setZip(String zip) { this.zip = zip; }