From d653b51de7fa5b3dfd6f619033a928b793836e90 Mon Sep 17 00:00:00 2001 From: Maria-Minerva Vonica Date: Thu, 28 Jan 2021 12:53:16 +0200 Subject: [PATCH] Fixed bad time bug. --- src/main/java/STPTMain.java | 7 ------- src/main/java/models/Time.java | 31 +++++++++++++++++++------------ test.xml | 28 ++++++++++++++++++++++------ test_data.txt | 9 +++++++++ 4 files changed, 50 insertions(+), 25 deletions(-) create mode 100644 test_data.txt diff --git a/src/main/java/STPTMain.java b/src/main/java/STPTMain.java index e19204e..fcb17d4 100644 --- a/src/main/java/STPTMain.java +++ b/src/main/java/STPTMain.java @@ -10,13 +10,6 @@ public class STPTMain { public static void main(String args[]) throws Exception { - WebService ws = new WebService( - "data/vehicles.xml", - "data/timetables.xml", - "data/statii-ratt.xml" - ); - //ws.getLastDepartureVehicle("5841"); - ws.getLastArrivalVehicle("5841"); Main main = new Main(); main.configure().addRoutesBuilder(new CamelREST()); main.configure().addRoutesBuilder(new CamelWebService()); diff --git a/src/main/java/models/Time.java b/src/main/java/models/Time.java index 928b150..eef6908 100644 --- a/src/main/java/models/Time.java +++ b/src/main/java/models/Time.java @@ -4,14 +4,14 @@ /** * Class which holds the implementation for time handling. - * + *

* Time is used by the timetable element, through the arrival element. */ public class Time { @XmlValue public String time; - public Time(){ + public Time() { } /** @@ -20,19 +20,20 @@ public Time(){ * @param time1 Time: A Time object of the form: hh:mm. * @param time2 Time: A Time object of the form: hh:mm. * @return int: 0 if equality, - * 1 if time1 bigger time2 - * -1 if time1 smaller time2 + * 1 if time1 bigger time2 + * -1 if time1 smaller time2 */ public int compareTime(String time1, String time2) { String[] splitTime1 = time1.split(":"); String[] splitTime2 = time2.split(":"); - if (!(validateTime(splitTime1[0]) && - validateTime(splitTime1[1]) && - validateTime(splitTime2[0]) && - validateTime(splitTime2[1]))) { + if (!(isInteger(splitTime1[0]) && + isInteger(splitTime1[1]) && + isInteger(splitTime2[0]) && + isInteger(splitTime2[1]))) { return 2; } + int time1Hour = Integer.parseInt(splitTime1[0]); int time1Minutes = Integer.parseInt(splitTime1[1]); @@ -48,14 +49,20 @@ public int compareTime(String time1, String time2) { } } - private boolean validateTime(String time) { - return !time.equals("**"); + public boolean isInteger(String input) { + try { + Integer.parseInt(input); + return true; + } catch (NumberFormatException e) { + return false; + } } - public Time(String time){ + + public Time(String time) { this.time = time; } - public String toString(){ + public String toString() { return this.time; } } \ No newline at end of file diff --git a/test.xml b/test.xml index 9a61c6c..6beb526 100644 --- a/test.xml +++ b/test.xml @@ -1,14 +1,30 @@ - 1746 - **:** + 2426 + 16:10 - 2006 - 18:22 + 2446 + 15:38 - 2786 - 16:12 + 1066 + 3 min. + + + 1550 + 3 min. + + + 2646 + 16:11 + + + 1266 + 5 min. + + + 2846 + 9 min. diff --git a/test_data.txt b/test_data.txt new file mode 100644 index 0000000..51f1013 --- /dev/null +++ b/test_data.txt @@ -0,0 +1,9 @@ +stationId's: + +8661 (doesn't have departures, so for getAllDeparturesForStation it will return an empty XML response and for getLastDepartureForStation the same." +7121 +8640 +3650 +3648 +10185 +5841 \ No newline at end of file