Skip to content

Commit

Permalink
Raw entity ids support
Browse files Browse the repository at this point in the history
  • Loading branch information
tomershefi committed Jan 31, 2024
1 parent ec7e84f commit 1c0ef7e
Show file tree
Hide file tree
Showing 7 changed files with 125 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -116,6 +116,7 @@ protected void save(GtfsMergeContext context, IdentityBean<?> entity) {
for (StopTime stopTime : stopTimes) {
stopTime.setId(0);
stopTime.setTrip(trip);
stopTime.setRawTripId(trip.getId().getId());
target.saveEntity(stopTime);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,10 @@ public class StopTimeArray extends AbstractList<StopTime> {
private double[] safeFactors = new double[0];

private String[] freeRunningFlags = new String[0];


private String[] rawTripIds = new String[0];
private String[] rawStopIds = new String[0];

public void trimToSize() {
setLength(size);
}
Expand Down Expand Up @@ -105,6 +108,8 @@ public boolean add(StopTime stopTime) {
meanOffsets[index] = stopTime.getMeanDurationOffset();
meanFactors[index] = stopTime.getMeanDurationFactor();
freeRunningFlags[index] = stopTime.getFreeRunningFlag();
rawTripIds[index] = stopTime.getRawTripId();
rawStopIds[index] = stopTime.getRawStopId();

return true;
}
Expand Down Expand Up @@ -167,6 +172,8 @@ private void setLength(int newLength) {
this.meanOffsets = Arrays.copyOf(this.meanOffsets, newLength);
this.meanFactors = Arrays.copyOf(this.meanFactors, newLength);
this.freeRunningFlags = Arrays.copyOf(this.freeRunningFlags, newLength);
this.rawTripIds = Arrays.copyOf(this.rawTripIds, newLength);
this.rawStopIds = Arrays.copyOf(this.rawStopIds, newLength);
}

private class StopTimeIterator implements Iterator<StopTime> {
Expand Down Expand Up @@ -472,5 +479,23 @@ public String getFreeRunningFlag() {
public void setFreeRunningFlag(String freeRunningFlag) {
freeRunningFlags[index] = freeRunningFlag;
}

@Override
public String getRawTripId() {
return rawTripIds[index];
}

@Override
public void setRawTripId(String rawTripId) {
rawTripIds[index] = rawTripId;
}

@Override
public String getRawStopId() {
return rawStopIds[index];
}

@Override
public void setRawStopId(String rawStopId) {rawStopIds[index] = rawStopId;}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public final class FareRule extends IdentityBean<Integer> {
@CsvField(name = "route_id", optional = true, mapping = EntityFieldMappingFactory.class)
private Route route;

@CsvField(optional = true, name = "route_id")
private String rawRouteId;

@CsvField(optional = true)
private String originId;

Expand All @@ -53,6 +56,7 @@ public FareRule(FareRule fr) {
this.originId = fr.originId;
this.destinationId = fr.destinationId;
this.containsId = fr.containsId;
this.rawRouteId = fr.rawRouteId;
}

@Override
Expand Down Expand Up @@ -81,6 +85,14 @@ public void setRoute(Route route) {
this.route = route;
}

public String getRawRouteId() {
return rawRouteId;
}

public void setRawRouteId(String rawRouteId) {
this.rawRouteId = rawRouteId;
}

public String getOriginId() {
return originId;
}
Expand Down
12 changes: 12 additions & 0 deletions onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/model/Route.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public final class Route extends IdentityBean<AgencyAndId> {
@CsvField(name = "agency_id", optional = true, mapping = RouteAgencyFieldMappingFactory.class, order = -1)
private Agency agency;

@CsvField(optional = true, name = "agency_id")
private String rawAgencyId;

@CsvField(optional = true, alwaysIncludeInOutput = true)
private String shortName;

Expand Down Expand Up @@ -99,6 +102,7 @@ public Route(Route r) {
this.brandingUrl = r.brandingUrl;
this.eligibilityRestricted = r.eligibilityRestricted;
this.regionalFareCardAccepted = r.regionalFareCardAccepted;
this.rawAgencyId = r.rawAgencyId;
}

public AgencyAndId getId() {
Expand All @@ -117,6 +121,14 @@ public void setAgency(Agency agency) {
this.agency = agency;
}

public String getRawAgencyId() {
return rawAgencyId;
}

public void setRawAgencyId(String rawAgencyId) {
this.rawAgencyId = rawAgencyId;
}

public String getShortName() {
return shortName;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,12 +42,19 @@ public final class StopTime extends IdentityBean<Integer> implements
@CsvField(name = "trip_id", mapping = EntityFieldMappingFactory.class)
private Trip trip;

@CsvField(optional = true, name = "trip_id")
private String rawTripId;

/**
* This is optional because in flex you can also have location_id and location_group_id.
*/

@CsvField(name = "stop_id", optional = true, mapping = StopLocationFieldMappingFactory.class)
private StopLocation stop;

@CsvField(optional = true, name = "stop_id")
private String rawStopId;

@CsvField(name = "location_id", optional = true, mapping = StopLocationFieldMappingFactory.class)
private StopLocation location;

Expand Down Expand Up @@ -181,6 +188,8 @@ public final class StopTime extends IdentityBean<Integer> implements

@CsvField(optional = true, name = "free_running_flag")
private String freeRunningFlag;



public StopTime() {

Expand Down Expand Up @@ -223,6 +232,8 @@ public StopTime(StopTime st) {
this.meanDurationOffset= st.meanDurationOffset;
this.meanDurationFactor= st.meanDurationFactor;
this.freeRunningFlag = st.freeRunningFlag;
this.rawTripId = st.rawTripId;
this.rawStopId = st.rawStopId;
}

public Integer getId() {
Expand Down Expand Up @@ -806,6 +817,39 @@ public void setFreeRunningFlag(String freeRunningFlag) {
}
this.freeRunningFlag = freeRunningFlag;
}

public String getRawTripId() {
if (proxy != null) {
return proxy.getRawTripId();
}
return rawTripId;
}


public void setRawTripId(String rawTripId) {
if (proxy != null) {
proxy.setRawTripId(rawTripId);
return;
}
this.rawTripId = rawTripId;
}

public String getRawStopId() {
if (proxy != null) {
return proxy.getRawStopId();
}
return rawStopId;
}


public void setRawStopId(String rawStopId) {
if (proxy != null) {
proxy.setRawStopId(rawStopId);
return;
}
this.rawStopId = rawStopId;
}

@Deprecated
public void setOldSpellingOfStartPickupDropOffWindow(int time) {
oldDropOffSpellingWarning("start");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -130,4 +130,11 @@ public interface StopTimeProxy {

public void setFreeRunningFlag(String freeRunningFlag);

public String getRawTripId();

public void setRawTripId(String rawTripId);

public String getRawStopId();

public void setRawStopId(String rawStopId);
}
23 changes: 23 additions & 0 deletions onebusaway-gtfs/src/main/java/org/onebusaway/gtfs/model/Trip.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,9 +32,14 @@ public final class Trip extends IdentityBean<AgencyAndId> {
@CsvField(name = "route_id", mapping = EntityFieldMappingFactory.class, order = -1)
private Route route;

@CsvField(optional = true, name = "route_id", order = -2)
private String rawRouteId;

@CsvField(mapping = DefaultAgencyIdFieldMappingFactory.class)
private AgencyAndId serviceId;

@CsvField(optional = true, name = "service_id")
private String rawServiceId;
@CsvField(optional = true)
private String tripShortName;

Expand Down Expand Up @@ -158,6 +163,8 @@ public Trip(Trip obj) {
this.peakOffpeak = obj.peakOffpeak;
this.mtaTripId = obj.mtaTripId;
this.boardingType = obj.boardingType;
this.rawRouteId = obj.rawRouteId;
this.rawServiceId = obj.rawServiceId;
}

public AgencyAndId getId() {
Expand All @@ -176,6 +183,14 @@ public void setRoute(Route route) {
this.route = route;
}

public String getRawRouteId() {
return rawRouteId;
}

public void setRawRouteId(String rawRouteId) {
this.rawRouteId = rawRouteId;
}

public AgencyAndId getServiceId() {
return serviceId;
}
Expand All @@ -184,6 +199,14 @@ public void setServiceId(AgencyAndId serviceId) {
this.serviceId = serviceId;
}

public String getRawServiceId() {
return rawServiceId;
}

public void setRawServiceId(String rawServiceId) {
this.rawServiceId = rawServiceId;
}

public String getTripShortName() {
return tripShortName;
}
Expand Down

0 comments on commit 1c0ef7e

Please sign in to comment.