Skip to content

Commit

Permalink
Improve name handling
Browse files Browse the repository at this point in the history
  • Loading branch information
leonardehrenfried committed Jul 24, 2023
1 parent 34b3f78 commit d9f5ed4
Show file tree
Hide file tree
Showing 4 changed files with 46 additions and 39 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,45 @@
import java.util.Set;

public class StopArea extends IdentityBean<AgencyAndId> implements StopLocation {
private static final long serialVersionUID = 1L;

private AgencyAndId id;
private static final long serialVersionUID = 1L;

private Set<StopLocation> stops = new HashSet<>();
private Area area;

private String name;
private Set<StopLocation> stops = new HashSet<>();

@Override
public AgencyAndId getId() {
return id;
}
@Override
public AgencyAndId getId() {
return area.getId();
}

public void setId(AgencyAndId id) {
this.id = id;
}
@Override
public void setId(AgencyAndId id) {
}

public Set<StopLocation> getLocations() {
return stops;
}
public void setArea(Area area) {
this.area = area;
}

private void setLocations(Set<StopLocation> stops) {
this.stops = stops;
}
public Set<StopLocation> getLocations() {
return stops;
}

public void addLocation(StopLocation location) {
this.stops.add(location);
}
private void setLocations(Set<StopLocation> stops) {
this.stops = stops;
}

public String getName() {
return name;
}
public void addLocation(StopLocation location) {
this.stops.add(location);
}

public String getName() {
return area.getName();
}

@Override
public void setName(String name) {

}

public void setName(String name) {
this.name = name;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -17,33 +17,33 @@

import org.onebusaway.csv_entities.schema.annotations.CsvField;
import org.onebusaway.csv_entities.schema.annotations.CsvFields;
import org.onebusaway.gtfs.serialization.mappings.DefaultAgencyIdFieldMappingFactory;
import org.onebusaway.gtfs.serialization.mappings.EntityFieldMappingFactory;
import org.onebusaway.gtfs.serialization.mappings.StopLocationFieldMappingFactory;

@CsvFields(filename = "stop_areas.txt", required = false)
public final class StopAreaElement extends IdentityBean<AgencyAndId> {

@CsvField(name = "area_id", mapping = DefaultAgencyIdFieldMappingFactory.class)
private AgencyAndId areaId;
@CsvField(name = "area_id", mapping = EntityFieldMappingFactory.class)
private Area area;
@CsvField(name = "stop_id", mapping = StopLocationFieldMappingFactory.class)
private StopLocation stopLocation;

public void setAreaId(AgencyAndId id) {
this.areaId = id;
public void setArea(Area area) {
this.area = area;
}

public AgencyAndId getAreaId() {
return areaId;
public Area getArea() {
return area;
}

@Override
public AgencyAndId getId() {
return new AgencyAndId(areaId.getAgencyId(), String.format("%s_%s", areaId.getId(), stopLocation.getId().getId()));
return new AgencyAndId(getArea().getId().getAgencyId(), String.format("%s_%s", area.getId().getId(), stopLocation.getId().getId()));
}

@Override
public void setId(AgencyAndId id) {
this.areaId = id;

}

public void setStopLocation(StopLocation stopLocation) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -355,6 +355,7 @@ public void handleEntity(Object entity) {
} else if (entity instanceof Area) {
Area area = (Area) entity;
registerAgencyId(Area.class, area.getId());

} else if (entity instanceof Location) {
Location location = (Location) entity;
registerAgencyId(Location.class, location.getId());
Expand All @@ -370,11 +371,10 @@ public void handleEntity(Object entity) {
locationGroup.addLocation(locationGroupElement.getLocation());
} else if (entity instanceof StopAreaElement) {
var stopAreaElement = (StopAreaElement) entity;
var stopArea = _entityStore.getEntityForId(StopArea.class, stopAreaElement.getAreaId());
var stopArea = _entityStore.getEntityForId(StopArea.class, stopAreaElement.getArea().getId());
if (stopArea == null) {
stopArea = new StopArea();
stopArea.setId(stopAreaElement.getAreaId());
stopArea.setName("area");
stopArea.setArea(stopAreaElement.getArea());
_entityStore.saveEntity(stopArea);
}
stopArea.addLocation(stopAreaElement.getStopLocation());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,7 @@ public void pierceTransitStopAreas() throws CsvEntityIOException, IOException {
assertEquals(15, areaElements.size());

var first = areaElements.get(0);
assertEquals("4210813", first.getAreaId().getId());
assertEquals("1_4210813", first.getArea().getId().toString());
var stop = first.getStopLocation();
assertEquals("4210806", stop.getId().getId());
assertEquals("Bridgeport Way & San Francisco Ave SW (Northbound)", stop.getName());
Expand Down Expand Up @@ -78,6 +78,8 @@ public void pierceTransitStopAreas() throws CsvEntityIOException, IOException {
var classes = stopTimes.stream().map(st -> st.getStop().getClass()).collect(Collectors.toList());
assertEquals(List.of(StopArea.class, StopArea.class), classes);

assertEquals("JBLM Stops", area.getName());

}

private static StopArea getArea(List<StopArea> stopAreas, String id) {
Expand Down

0 comments on commit d9f5ed4

Please sign in to comment.