Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/backend/Palina.java
Show All 27 Lines | |||||
/** | /** | ||||
* Timetable for multiple routes.<br> | * Timetable for multiple routes.<br> | ||||
* <br> | * <br> | ||||
* Apparently "palina" and a bunch of other terms can't really be translated into English.<br> | * Apparently "palina" and a bunch of other terms can't really be translated into English.<br> | ||||
* Not in a way that makes sense and keeps the code readable, at least. | * Not in a way that makes sense and keeps the code readable, at least. | ||||
*/ | */ | ||||
public class Palina extends Stop { | public class Palina extends Stop { | ||||
private ArrayList<Route> routes = new ArrayList<>(); | private ArrayList<Route> routes = new ArrayList<>(); | ||||
private boolean routesModified = false; | |||||
private Passaggio.Source allSource = null; | |||||
public Palina(String stopID) { | public Palina(String stopID) { | ||||
super(stopID); | super(stopID); | ||||
} | } | ||||
public Palina(Stop s){ | public Palina(Stop s){ | ||||
super(s.ID,s.getStopDefaultName(),s.getStopUserName(),s.location,s.type, | super(s.ID,s.getStopDefaultName(),s.getStopUserName(),s.location,s.type, | ||||
s.getRoutesThatStopHere(),s.getLatitude(),s.getLongitude()); | s.getRoutesThatStopHere(),s.getLatitude(),s.getLongitude()); | ||||
} | } | ||||
/** | /** | ||||
* Adds a timetable entry to a route. | * Adds a timetable entry to a route. | ||||
* | * | ||||
* @param TimeGTT time in GTT format (e.g. "11:22*") | * @param TimeGTT time in GTT format (e.g. "11:22*") | ||||
* @param arrayIndex position in the array for this route (returned by addRoute) | * @param arrayIndex position in the array for this route (returned by addRoute) | ||||
*/ | */ | ||||
public void addPassaggio(String TimeGTT, Passaggio.Source src,int arrayIndex) { | public void addPassaggio(String TimeGTT, Passaggio.Source src,int arrayIndex) { | ||||
this.routes.get(arrayIndex).addPassaggio(TimeGTT,src); | this.routes.get(arrayIndex).addPassaggio(TimeGTT,src); | ||||
routesModified = true; | |||||
} | } | ||||
/** | /** | ||||
* Count routes with missing directions | * Count routes with missing directions | ||||
* @return number | * @return number | ||||
*/ | */ | ||||
public int countRoutesWithMissingDirections(){ | public int countRoutesWithMissingDirections(){ | ||||
int i = 0; | int i = 0; | ||||
for (Route r : routes){ | for (Route r : routes){ | ||||
if(r.destinazione==null||r.destinazione.equals("")) | if(r.destinazione==null||r.destinazione.equals("")) | ||||
i++; | i++; | ||||
} | } | ||||
return i; | return i; | ||||
} | } | ||||
/** | /** | ||||
* Adds a route to the timetable. | * Adds a route to the timetable. | ||||
* | * | ||||
* @param routeID name | * @param routeID name | ||||
* @param type bus, underground, railway, ... | * @param type bus, underground, railway, ... | ||||
* @param destinazione end of line\terminus (underground stations have the same ID for both directions) | * @param destinazione end of line\terminus (underground stations have the same ID for both directions) | ||||
* @return array index for this route | * @return array index for this route | ||||
*/ | */ | ||||
public int addRoute(String routeID, String destinazione, Route.Type type) { | public int addRoute(String routeID, String destinazione, Route.Type type) { | ||||
this.routes.add(new Route(routeID, destinazione, type, new ArrayList<Passaggio>(6))); | this.routes.add(new Route(routeID, destinazione, type, new ArrayList<>(6))); | ||||
routesModified = true; | |||||
return this.routes.size() - 1; // last inserted element and pray that direct access to ArrayList elements really is direct | return this.routes.size() - 1; // last inserted element and pray that direct access to ArrayList elements really is direct | ||||
} | } | ||||
public int addRoute(Route r){ | public int addRoute(Route r){ | ||||
this.routes.add(r); | this.routes.add(r); | ||||
routesModified = true; | |||||
return this.routes.size()-1; | return this.routes.size()-1; | ||||
} | } | ||||
public void setRoutes(List<Route> routeList){ | public void setRoutes(List<Route> routeList){ | ||||
routes = new ArrayList<>(routeList); | routes = new ArrayList<>(routeList); | ||||
} | } | ||||
// /** | // /** | ||||
▲ Show 20 Lines • Show All 54 Lines • ▼ Show 20 Lines | |||||
// /** | // /** | ||||
// * Gets the current timetable for this route, from its index in the array. | // * Gets the current timetable for this route, from its index in the array. | ||||
// * | // * | ||||
// * @return timetable (passaggi) | // * @return timetable (passaggi) | ||||
// */ | // */ | ||||
// public List<Passaggio> queryRouteByIndex(int index) { | // public List<Passaggio> queryRouteByIndex(int index) { | ||||
// return this.routes.get(index).getPassaggi(); | // return this.routes.get(index).getPassaggi(); | ||||
// } | // } | ||||
protected void checkPassaggi(){ | |||||
Passaggio.Source mSource = null; | |||||
for (Route r: routes){ | |||||
for(Passaggio pass: r.passaggi){ | |||||
if (mSource == null) { | |||||
mSource = pass.source; | |||||
} else if (mSource != pass.source){ | |||||
Log.w("BusTO-CheckPassaggi", | |||||
"Cannot determine the source, have got "+mSource +" so far, the next one is "+pass.source ); | |||||
mSource = Passaggio.Source.UNDETERMINED; | |||||
break; | |||||
} | |||||
} | |||||
if(mSource == Passaggio.Source.UNDETERMINED) | |||||
break; | |||||
} | |||||
//finished with the check, setting flags | |||||
routesModified = false; | |||||
allSource = mSource; | |||||
} | |||||
public Passaggio.Source getPassaggiSourceIfAny(){ | |||||
if(allSource==null || routesModified){ | |||||
checkPassaggi(); | |||||
} | |||||
assert allSource != null; | |||||
return allSource; | |||||
} | |||||
/** | /** | ||||
* Gets every route and its timetable. | * Gets every route and its timetable. | ||||
* | * | ||||
* @return routes and timetables. | * @return routes and timetables. | ||||
*/ | */ | ||||
public List<Route> queryAllRoutes() { | public List<Route> queryAllRoutes() { | ||||
return this.routes; | return this.routes; | ||||
▲ Show 20 Lines • Show All 67 Lines • ▼ Show 20 Lines | public int addInfoFromRoutes(List<Route> additionalRoutes){ | ||||
} | } | ||||
//found the correct correspondance | //found the correct correspondance | ||||
//MERGE INFO | //MERGE INFO | ||||
if(r.mergeRouteWithAnother(selected)) count++; | if(r.mergeRouteWithAnother(selected)) count++; | ||||
} | } | ||||
return count; | return count; | ||||
} | } | ||||
// /** | // /** | ||||
// * Route with terminus (destinazione) and timetables (passaggi), internal implementation. | // * Route with terminus (destinazione) and timetables (passaggi), internal implementation. | ||||
// * | // * | ||||
// * Contains mostly the same data as the Route public class, but methods are quite different and extending Route doesn't really work, here. | // * Contains mostly the same data as the Route public class, but methods are quite different and extending Route doesn't really work, here. | ||||
// */ | // */ | ||||
// private final class RouteInternal { | // private final class RouteInternal { | ||||
// public final String name; | // public final String name; | ||||
// public final String destinazione; | // public final String destinazione; | ||||
▲ Show 20 Lines • Show All 63 Lines • ▼ Show 20 Lines | |||||
// * | // * | ||||
// * @return times from the timetable | // * @return times from the timetable | ||||
// */ | // */ | ||||
// public List<Passaggio> getPassaggi() { | // public List<Passaggio> getPassaggi() { | ||||
// return this.passaggi; | // return this.passaggi; | ||||
// } | // } | ||||
// } | // } | ||||
} | } | ||||
No newline at end of file | No newline at end of file |
Public contents are in Creative Commons Attribution-ShareAlike 4.0 (CC-BY-SA) or GNU Free Documentation License (at your option) unless otherwise noted. · Contact / Register