Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/backend/Route.java
Show First 20 Lines • Show All 158 Lines • ▼ Show 20 Lines | public class Route implements Comparable<Route> { | ||||
*/ | */ | ||||
public void addPassaggio(String TimeGTT, Passaggio.Source source) { | public void addPassaggio(String TimeGTT, Passaggio.Source source) { | ||||
this.passaggi.add(new Passaggio(TimeGTT, source)); | this.passaggi.add(new Passaggio(TimeGTT, source)); | ||||
} | } | ||||
//Overloaded | //Overloaded | ||||
public void addPassaggio(int hour, int minutes, boolean realtime, Passaggio.Source source) { | public void addPassaggio(int hour, int minutes, boolean realtime, Passaggio.Source source) { | ||||
this.passaggi.add(new Passaggio(hour, minutes, realtime, source)); | this.passaggi.add(new Passaggio(hour, minutes, realtime, source)); | ||||
} | } | ||||
public static Route.Type getTypeFromSymbol(String route) { | |||||
switch (route) { | |||||
case "M": | |||||
return Route.Type.METRO; | |||||
case "T": | |||||
return Route.Type.RAILWAY; | |||||
} | |||||
// default with case "B" | |||||
return Route.Type.BUS; | |||||
} | |||||
private String parseDestinazione(String direzione){ | private String parseDestinazione(String direzione){ | ||||
if(direzione==null) return null; | if(direzione==null) return null; | ||||
//trial to add space to the parenthesis | //trial to add space to the parenthesis | ||||
String[] exploded = direzione.split("\\("); | String[] exploded = direzione.split("\\("); | ||||
if(exploded.length>1){ | if(exploded.length>1){ | ||||
StringBuilder sb = new StringBuilder(); | StringBuilder sb = new StringBuilder(); | ||||
sb.append(exploded[0]); | sb.append(exploded[0]); | ||||
for(int i=1; i<exploded.length;i++) { | for(int i=1; i<exploded.length;i++) { | ||||
▲ Show 20 Lines • Show All 49 Lines • ▼ Show 20 Lines | public String getPassaggiToString(int start_idx, int number, boolean sort){ | ||||
// "+" calls concat() and some other stuff internally, this should be faster | // "+" calls concat() and some other stuff internally, this should be faster | ||||
//StringBuilder is THE WAY | //StringBuilder is THE WAY | ||||
sb.append(arrivals.get(j).toString()); | sb.append(arrivals.get(j).toString()); | ||||
sb.append(" "); | sb.append(" "); | ||||
} | } | ||||
return sb.toString(); | return sb.toString(); | ||||
} | } | ||||
@Override | @Override | ||||
public int compareTo(@NonNull Route other) { | public int compareTo(@NonNull Route other) { | ||||
int res; | int res; | ||||
int thisAsInt, otherAsInt; | int thisAsInt, otherAsInt; | ||||
// sorting by numbers alone yields a far more "natural" result (36N goes before 2024, 95B next to 95, and the like) | // sorting by numbers alone yields a far more "natural" result (36N goes before 2024, 95B next to 95, and the like) | ||||
thisAsInt = networkTools.failsafeParseInt(this.name.replaceAll("[^0-9]", "")); | thisAsInt = networkTools.failsafeParseInt(this.name.replaceAll("[^0-9]", "")); | ||||
▲ Show 20 Lines • Show All 117 Lines • Show Last 20 Lines |
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