Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
22 changes: 22 additions & 0 deletions src/main/java/org/mtransit/android/commons/data/Schedule.java
Original file line number Diff line number Diff line change
Expand Up @@ -436,6 +436,7 @@ public String getLogTag() {
private Integer accessible = null;
@Nullable
private String tripId = null; // will store trip ID int initially but replaced with real trip ID soon after
private int stopSequence = -1;
@Nullable
private Long arrivalDiffMs = null;

Expand Down Expand Up @@ -630,6 +631,15 @@ public void setTripId(@Nullable String tripId) {
this.tripId = tripId;
}

public void setStopSequence(int stopSequence) {
this.stopSequence = stopSequence;
}

@Nullable
public Integer getStopSequenceOrNull() {
return stopSequence < 0 ? null : stopSequence;
}

@Nullable
public String getTripId() {
return tripId;
Expand All @@ -651,6 +661,7 @@ public boolean equals(Object o) {
if (!Objects.equals(oldSchedule, timestamp.oldSchedule)) return false;
if (!Objects.equals(accessible, timestamp.accessible)) return false;
if (!Objects.equals(tripId, timestamp.tripId)) return false;
if (stopSequence != timestamp.stopSequence) return false;
if (!Objects.equals(arrivalDiffMs, timestamp.arrivalDiffMs)) return false;
// if (!Objects.equals(heading, timestamp.heading)) return false; // LAZY
return true;
Expand All @@ -666,6 +677,7 @@ public int hashCode() {
result = 31 * result + (oldSchedule != null ? oldSchedule.hashCode() : 0);
result = 31 * result + (accessible != null ? accessible : 0);
result = 31 * result + (tripId != null ? tripId.hashCode() : 0);
result = 31 * result + stopSequence;
result = 31 * result + (arrivalDiffMs != null ? arrivalDiffMs.hashCode() : 0);
// result = 31 * result + (heading != null ? heading.hashCode() : 0); // LAZY
return result;
Expand All @@ -683,6 +695,9 @@ public String toString() {
if (tripId != null) {
sb.append(", tripId:'").append(tripId).append('\'');
}
if (stopSequence >= 0) {
sb.append(", seq:").append(stopSequence);
}
if (headsignType != Direction.HEADSIGN_TYPE_NONE) {
sb.append(", ht:").append(headsignType);
}
Expand All @@ -708,6 +723,7 @@ public String toString() {
private static final String JSON_TIMESTAMP = "t";
private static final String JSON_ARRIVAL_DIFF = "tDiffA";
private static final String JSON_TRIP_ID = "trip_id";
private static final String JSON_STOP_SEQUENCE = "stop_seq";
private static final String JSON_HEADSIGN_TYPE = "ht";
private static final String JSON_HEADSIGN_VALUE = "hv";
private static final String JSON_LOCAL_TIME_ZONE = "localTimeZone";
Expand All @@ -726,6 +742,9 @@ static Timestamp parseJSON(@NonNull JSONObject jTimestamp) {
if (jTimestamp.has(JSON_TRIP_ID)) {
timestamp.setTripId(jTimestamp.getString(JSON_TRIP_ID));
}
if (jTimestamp.has(JSON_STOP_SEQUENCE)) {
timestamp.setStopSequence(jTimestamp.getInt(JSON_STOP_SEQUENCE));
}
final int headSignType = jTimestamp.optInt(JSON_HEADSIGN_TYPE, -1);
final String headSignValue = jTimestamp.optString(JSON_HEADSIGN_VALUE, StringUtils.EMPTY);
if (headSignType >= 0 && !headSignValue.isEmpty()) {
Expand Down Expand Up @@ -771,6 +790,9 @@ public static JSONObject toJSON(@NonNull Timestamp timestamp) {
if (timestamp.tripId != null) {
jTimestamp.put(JSON_TRIP_ID, timestamp.tripId);
}
if (timestamp.stopSequence >= 0) {
jTimestamp.put(JSON_STOP_SEQUENCE, timestamp.stopSequence);
}
if (timestamp.headsignType != Direction.HEADSIGN_TYPE_NONE && timestamp.headsignValue != null) {
jTimestamp.put(JSON_HEADSIGN_TYPE, timestamp.headsignType);
jTimestamp.put(JSON_HEADSIGN_VALUE, timestamp.headsignValue);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -356,6 +356,7 @@ private static String getSTOP_SCHEDULE_RAW_FILE_FORMAT(@NonNull Context context)
private static final int GTFS_SCHEDULE_STOP_FILE_COL_DEPARTURE_IDX;
private static final int GTFS_SCHEDULE_STOP_FILE_COL_ARRIVAL_DIFF_IDX;
private static final int GTFS_SCHEDULE_STOP_FILE_COL_TRIP_ID_IDX;
private static final int GTFS_SCHEDULE_STOP_FILE_COL_STOP_SEQUENCE_IDX;
private static final int GTFS_SCHEDULE_STOP_FILE_COL_HEADSIGN_TYPE_IDX;
private static final int GTFS_SCHEDULE_STOP_FILE_COL_HEADSIGN_VALUE_IDX;
private static final int GTFS_SCHEDULE_STOP_FILE_COL_ACCESSIBLE_IDX;
Expand Down Expand Up @@ -385,6 +386,11 @@ private static String getSTOP_SCHEDULE_RAW_FILE_FORMAT(@NonNull Context context)
GTFS_SCHEDULE_STOP_FILE_COL_ARRIVAL_DIFF_IDX = -1;
GTFS_SCHEDULE_STOP_FILE_COL_TRIP_ID_IDX = -1;
}
if (FeatureFlags.F_EXPORT_STOP_SEQUENCE) {
GTFS_SCHEDULE_STOP_FILE_COL_STOP_SEQUENCE_IDX = ++idx;
} else {
GTFS_SCHEDULE_STOP_FILE_COL_STOP_SEQUENCE_IDX = -1;
}
GTFS_SCHEDULE_STOP_FILE_COL_HEADSIGN_TYPE_IDX = ++idx;
GTFS_SCHEDULE_STOP_FILE_COL_HEADSIGN_VALUE_IDX = ++idx;
GTFS_SCHEDULE_STOP_FILE_COL_ACCESSIBLE_IDX = ++idx;
Expand All @@ -396,7 +402,7 @@ private static String getSTOP_SCHEDULE_RAW_FILE_FORMAT(@NonNull Context context)
@NonNull
static Set<Schedule.Timestamp> findScheduleList(
@NonNull GTFSProvider provider,
@SuppressWarnings("unused") long routeId, // included inside direction Id
@SuppressWarnings("unused") long routeId, // included inside direction ID
long directionId, // includes routeId,
int stopId,
String dateS, String timeS,
Expand Down Expand Up @@ -430,6 +436,7 @@ static Set<Schedule.Timestamp> findScheduleList(
Long arrivalTimestampMs;
Schedule.Timestamp timestamp;
String tripIdOrInt;
String stopSequenceS;
String headsignTypeS;
Integer headsignType;
String accessibleS;
Expand Down Expand Up @@ -487,8 +494,14 @@ static Set<Schedule.Timestamp> findScheduleList(
}
}
}
if (GTFS_SCHEDULE_STOP_FILE_COL_STOP_SEQUENCE_IDX >= 0) {
stopSequenceS = lineItems[GTFS_SCHEDULE_STOP_FILE_COL_STOP_SEQUENCE_IDX + extraIdx];
if (!TextUtils.isEmpty(stopSequenceS) && CharUtils.isDigitsOnly(stopSequenceS)) {
timestamp.setStopSequence(Integer.parseInt(stopSequenceS));
}
}
headsignTypeS = lineItems[GTFS_SCHEDULE_STOP_FILE_COL_HEADSIGN_TYPE_IDX + extraIdx];
headsignType = TextUtils.isEmpty(headsignTypeS) ? null : Integer.valueOf(headsignTypeS);
headsignType = TextUtils.isEmpty(headsignTypeS) || !CharUtils.isDigitsOnly(headsignTypeS) ? null : Integer.parseInt(headsignTypeS);
if (headsignType != null && headsignType >= 0) {
timestamp.setHeadsign(
headsignType,
Expand All @@ -498,7 +511,7 @@ static Set<Schedule.Timestamp> findScheduleList(
timestamp.setOldSchedule(diffWithRealityInMs > 0L);
timestamp.setRealTime(false); // static
accessibleS = lineItems[GTFS_SCHEDULE_STOP_FILE_COL_ACCESSIBLE_IDX + extraIdx];
accessible = TextUtils.isEmpty(accessibleS) ? null : Integer.valueOf(accessibleS);
accessible = TextUtils.isEmpty(accessibleS) || !CharUtils.isDigitsOnly(accessibleS) ? null : Integer.parseInt(accessibleS);
if (accessible != null && accessible >= 0) {
timestamp.setAccessible(accessible);
}
Expand Down Expand Up @@ -634,7 +647,7 @@ private static HashSet<Schedule.Frequency> findFrequencyList(@NonNull GTFSProvid
long routeId, long directionId,
String dateS, String timeS,
long diffWithRealityInMs) {
long timeI = Integer.parseInt(timeS);
long timeI = Long.parseLong(timeS);
final HashSet<Schedule.Frequency> result = new HashSet<>();
final Set<Pair<String, Integer>> serviceIdOrIntAndExceptionTypes = findServicesAndExceptionTypes(provider, dateS);
final Set<String> serviceIdOrInts = filterServiceIdOrInts(serviceIdOrIntAndExceptionTypes, diffWithRealityInMs > 0L);
Expand Down Expand Up @@ -683,7 +696,7 @@ private static HashSet<Schedule.Frequency> findFrequencyList(@NonNull GTFSProvid
startTime = Integer.parseInt(lineItems[GTFS_ROUTE_FREQUENCY_FILE_COL_START_TIME_IDX]);
tStartTimeInMs = convertToTimestamp(context, startTime, dateS);
tEndTimeInMs = convertToTimestamp(context, endTime, dateS);
tHeadway = Integer.valueOf(lineItems[GTFS_ROUTE_FREQUENCY_FILE_COL_HEADWAY_IDX]);
tHeadway = Integer.parseInt(lineItems[GTFS_ROUTE_FREQUENCY_FILE_COL_HEADWAY_IDX]);
//noinspection ConstantConditions
if (tStartTimeInMs != null && tEndTimeInMs != null && tHeadway != null) {
result.add(new Schedule.Frequency(
Expand Down