Skip to content

Commit

Permalink
Fixed bad time bug.
Browse files Browse the repository at this point in the history
  • Loading branch information
BabyCakes13 committed Jan 28, 2021
1 parent f0f7f50 commit d653b51
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 25 deletions.
7 changes: 0 additions & 7 deletions src/main/java/STPTMain.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
31 changes: 19 additions & 12 deletions src/main/java/models/Time.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

/**
* Class which holds the implementation for time handling.
*
* <p>
* Time is used by the timetable element, through the arrival element.
*/
public class Time {
@XmlValue
public String time;

public Time(){
public Time() {
}

/**
Expand All @@ -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]);

Expand All @@ -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;
}
}
28 changes: 22 additions & 6 deletions test.xml
Original file line number Diff line number Diff line change
@@ -1,14 +1,30 @@
<?xml version="1.0" encoding="ISO-8859-1"?><vehicle-arrivals>
<vehicle-arrival>
<vehicle-id>1746</vehicle-id>
<arrival-time>**:**</arrival-time>
<vehicle-id>2426</vehicle-id>
<arrival-time>16:10</arrival-time>
</vehicle-arrival>
<vehicle-arrival>
<vehicle-id>2006</vehicle-id>
<arrival-time>18:22</arrival-time>
<vehicle-id>2446</vehicle-id>
<arrival-time>15:38</arrival-time>
</vehicle-arrival>
<vehicle-arrival>
<vehicle-id>2786</vehicle-id>
<arrival-time>16:12</arrival-time>
<vehicle-id>1066</vehicle-id>
<arrival-time>3 min.</arrival-time>
</vehicle-arrival>
<vehicle-arrival>
<vehicle-id>1550</vehicle-id>
<arrival-time>3 min.</arrival-time>
</vehicle-arrival>
<vehicle-arrival>
<vehicle-id>2646</vehicle-id>
<arrival-time>16:11</arrival-time>
</vehicle-arrival>
<vehicle-arrival>
<vehicle-id>1266</vehicle-id>
<arrival-time>5 min.</arrival-time>
</vehicle-arrival>
<vehicle-arrival>
<vehicle-id>2846</vehicle-id>
<arrival-time>9 min.</arrival-time>
</vehicle-arrival>
</vehicle-arrivals>
9 changes: 9 additions & 0 deletions test_data.txt
Original file line number Diff line number Diff line change
@@ -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

0 comments on commit d653b51

Please sign in to comment.