Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/backend/Route.java
Show All 39 Lines | public class Route implements Comparable<Route> { | ||||
public final Type type; | public final Type type; | ||||
public String description; | public String description; | ||||
//ordered list of stops, from beginning to end of line | //ordered list of stops, from beginning to end of line | ||||
private List<String> stopsList = null; | private List<String> stopsList = null; | ||||
public int branchid = BRANCHID_MISSING; | public int branchid = BRANCHID_MISSING; | ||||
public int[] serviceDays ={}; | public int[] serviceDays ={}; | ||||
//0=>feriale, 1=>festivo -2=>unknown | //0=>feriale, 1=>festivo -2=>unknown | ||||
public FestiveInfo festivo = FestiveInfo.UNKNOWN; | public FestiveInfo festivo = FestiveInfo.UNKNOWN; | ||||
private @Nullable String gtfsId; | |||||
public enum Type { // "long distance" sono gli extraurbani. | public enum Type { // "long distance" sono gli extraurbani. | ||||
BUS(1), LONG_DISTANCE_BUS(2), METRO(3), RAILWAY(4), TRAM(5), UNKNOWN(-2); | BUS(1), LONG_DISTANCE_BUS(2), METRO(3), RAILWAY(4), TRAM(5), UNKNOWN(-2); | ||||
//TODO: decide to give some special parameter to each field | //TODO: decide to give some special parameter to each field | ||||
private int code; | private int code; | ||||
Type(int code){ | Type(int code){ | ||||
this.code = code; | this.code = code; | ||||
▲ Show 20 Lines • Show All 181 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(); | ||||
} | } | ||||
public int numPassaggi(){ | |||||
if (passaggi==null) | |||||
return 0; | |||||
return passaggi.size(); | |||||
} | |||||
@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) | ||||
Show All 9 Lines | public int compareTo(@NonNull Route other) { | ||||
return res; | return res; | ||||
} | } | ||||
} else { | } else { | ||||
// non-numeric | // non-numeric | ||||
res = this.name.compareTo(other.name); | res = this.name.compareTo(other.name); | ||||
if (res != 0) { | if (res != 0) { | ||||
return res; | return res; | ||||
} | } | ||||
// compare gtfsID | |||||
if (this.gtfsId != null && other.gtfsId!=null){ | |||||
res = this.gtfsId.compareTo(other.gtfsId); | |||||
if (res!=0) return 0; | |||||
} | |||||
} | } | ||||
// try comparing their destination | // try comparing their destination | ||||
if(this.destinazione!=null){ | if(this.destinazione!=null){ | ||||
res = this.destinazione.compareTo(other.destinazione); | res = this.destinazione.compareTo(other.destinazione); | ||||
if(res != 0) { | if(res != 0) { | ||||
return res; | return res; | ||||
} | } | ||||
Show All 10 Lines | public int compareTo(@NonNull Route other) { | ||||
if(this.type != other.type) { | if(this.type != other.type) { | ||||
// ordinal() is evil or whatever, who cares. | // ordinal() is evil or whatever, who cares. | ||||
return this.type.ordinal() - other.type.ordinal(); | return this.type.ordinal() - other.type.ordinal(); | ||||
} | } | ||||
return 0; | return 0; | ||||
} | } | ||||
@Nullable | |||||
public String getGtfsId() { | |||||
return gtfsId; | |||||
} | |||||
public void setGtfsId(@Nullable String gtfsId) { | |||||
this.gtfsId = gtfsId; | |||||
} | |||||
public boolean isBranchIdValid(){ | public boolean isBranchIdValid(){ | ||||
return branchid!=BRANCHID_MISSING; | return branchid!=BRANCHID_MISSING; | ||||
} | } | ||||
@Override | @Override | ||||
public boolean equals(Object obj) { | public boolean equals(Object obj) { | ||||
if(obj instanceof Route){ | if(obj instanceof Route){ | ||||
Route r = (Route) obj; | Route r = (Route) obj; | ||||
boolean result = false; | boolean result = false; | ||||
if(this.name.equals(r.name) && this.branchid == r.branchid){ | if(this.name.equals(r.name) && this.branchid == r.branchid){ | ||||
if(description!=null && r.description!=null) | if(description!=null && r.description!=null) | ||||
if(!description.trim().equals(r.description.trim())) | if(!description.trim().equals(r.description.trim())) | ||||
return false; | return false; | ||||
if(destinazione!=null && r.destinazione!=null){ | if(destinazione!=null && r.destinazione!=null){ | ||||
if(!this.destinazione.trim().equals(r.destinazione.trim())) | if(!this.destinazione.trim().equals(r.destinazione.trim())) | ||||
// they are not the same | // they are not the same | ||||
return false; | return false; | ||||
} | } | ||||
if(gtfsId!=null && r.gtfsId!=null && !(gtfsId.trim().equals(r.gtfsId.trim()))) | |||||
return false; | |||||
//check stops list | //check stops list | ||||
if(this.stopsList!=null && r.stopsList!=null){ | if(this.stopsList!=null && r.stopsList!=null){ | ||||
int sizeDiff = this.stopsList.size()-r.stopsList.size(); | int sizeDiff = this.stopsList.size()-r.stopsList.size(); | ||||
if(sizeDiff!=0) { | if(sizeDiff!=0) { | ||||
return false; | return false; | ||||
} else { | } else { | ||||
//check that the stops are the same | //check that the stops are the same | ||||
▲ Show 20 Lines • Show All 61 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