Changeset View
Changeset View
Standalone View
Standalone View
src/it/reyboz/bustorino/backend/Passaggio.java
Show First 20 Lines • Show All 138 Lines • ▼ Show 20 Lines | private static String makePassaggioGTT(int hour, int minutes, boolean realtime){ | ||||
return sb.toString(); | return sb.toString(); | ||||
} | } | ||||
@Override | @Override | ||||
public int compareTo(@NonNull Passaggio other) { | public int compareTo(@NonNull Passaggio other) { | ||||
if(this.hh == UNKNOWN_TIME || other.hh == UNKNOWN_TIME) | if(this.hh == UNKNOWN_TIME || other.hh == UNKNOWN_TIME) | ||||
return 0; | return 0; | ||||
else { | else { | ||||
int diff = getMinutesDiff(other); | |||||
// we should take into account if one is in real time and the other isn't, shouldn't we? | |||||
if (other.isInRealTime) { | |||||
diff+=2; | |||||
} | |||||
if (this.isInRealTime) { | |||||
diff -=2; | |||||
} | |||||
return diff; | |||||
} | |||||
} | |||||
public int getMinutesDiff(Passaggio other){ | |||||
int diff = this.hh - other.hh; | int diff = this.hh - other.hh; | ||||
// an attempt to correctly sort arrival times around midnight (e.g. 23.59 should come before 00.01) | // an attempt to correctly sort arrival times around midnight (e.g. 23.59 should come before 00.01) | ||||
if (diff > 12) { // untested | if (diff > 12) { // untested | ||||
diff -= 24; | diff -= 24; | ||||
} else if (diff < -12) { | } else if (diff < -12) { | ||||
diff += 24; | diff += 24; | ||||
} | } | ||||
diff *= 60; | diff *= 60; | ||||
diff += this.mm - other.mm; | diff += this.mm - other.mm; | ||||
// we should take into account if one is in real time and the other isn't, shouldn't we? | |||||
if (other.isInRealTime) { | |||||
diff+=2; | |||||
} | |||||
if (this.isInRealTime) { | |||||
diff -=2; | |||||
} | |||||
return diff; | return diff; | ||||
} | } | ||||
} | |||||
// | // | ||||
// @Override | // @Override | ||||
// public String toString() { | // public String toString() { | ||||
// String resultString = (this.hh).concat(":").concat(this.mm); | // String resultString = (this.hh).concat(":").concat(this.mm); | ||||
// if(this.isInRealTime) { | // if(this.isInRealTime) { | ||||
// return resultString.concat("*"); | // return resultString.concat("*"); | ||||
// } else { | // } else { | ||||
// return resultString; | // return resultString; | ||||
// } | // } | ||||
// } | // } | ||||
public enum Source{ | public enum Source{ | ||||
FiveTAPI,GTTJSON,FiveTScraper,MatoAPI, UNDETERMINED | FiveTAPI,GTTJSON,FiveTScraper,MatoAPI, UNDETERMINED | ||||
} | } | ||||
} | } | ||||
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