Skip to content

Commit

Permalink
Use two separate methods for stop and location
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Nov 23, 2023
1 parent 9e81f73 commit abc5567
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,7 +279,7 @@ public StopLocation getStop() {
if (proxy != null) {
return proxy.getStop();
}
return Objects.requireNonNullElse(stop, location);
return stop;
}

public StopLocation getLocation() {
Expand All @@ -289,6 +289,15 @@ public StopLocation getLocation() {
return location;
}

/**
* Returns possible entity for the stop location in this order:
* - stop
* - location
*/
public StopLocation getStopLocation(){
return Objects.requireNonNullElseGet(getStop(), this::getLocation);
}

public void setStop(StopLocation stop) {
if (proxy != null) {
proxy.setStop(stop);
Expand Down Expand Up @@ -698,7 +707,7 @@ public String displayArrival() {

@Override
public String toString() {
return "StopTime(seq=" + getStopSequence() + " stop=" + (getStop()==null?"NuLl":getStop().getId())
return "StopTime(seq=" + getStopSequence() + " stop=" + (getStopLocation()==null?"NuLl":getStop().getId())
+ " trip=" + (getTrip()==null?"NuLl":getTrip().getId()) + " times="
+ StopTimeFieldMappingFactory.getSecondsAsString(getArrivalTime())
+ "-"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,9 +89,9 @@ public void locationIdAsASeparateColumn() throws CsvEntityIOException, IOExcepti
var dao = processFeed(GtfsTestData.getBrownCountyFlex(), AGENCY_ID, false);
var trip = dao.getAllTrips().stream().filter(t -> t.getId().getId().equals("t_5374696_b_77497_tn_0")).findAny().get();
var stopTimes = dao.getStopTimesForTrip(trip);
stopTimes.forEach(st -> assertNotNull(st.getStop()));
stopTimes.forEach(st -> assertNotNull(st.getStopLocation()));

var stopLocations = stopTimes.stream().map(StopTime::getStop).collect(Collectors.toList());
var stopLocations = stopTimes.stream().map(StopTime::getStopLocation).collect(Collectors.toList());
var first = stopLocations.get(0);
assertEquals("4149546", first.getId().getId());
assertEquals(Stop.class, first.getClass());
Expand Down

0 comments on commit abc5567

Please sign in to comment.