
org.opentripplanner.transit.service.StopModelBuilder Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of otp Show documentation
Show all versions of otp Show documentation
The OpenTripPlanner multimodal journey planning system
The newest version!
package org.opentripplanner.transit.service;
import java.util.Collection;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.function.Function;
import org.opentripplanner.transit.model.framework.DefaultEntityById;
import org.opentripplanner.transit.model.framework.EntityById;
import org.opentripplanner.transit.model.framework.FeedScopedId;
import org.opentripplanner.transit.model.framework.ImmutableEntityById;
import org.opentripplanner.transit.model.site.AreaStop;
import org.opentripplanner.transit.model.site.AreaStopBuilder;
import org.opentripplanner.transit.model.site.GroupOfStations;
import org.opentripplanner.transit.model.site.GroupStop;
import org.opentripplanner.transit.model.site.GroupStopBuilder;
import org.opentripplanner.transit.model.site.MultiModalStation;
import org.opentripplanner.transit.model.site.RegularStop;
import org.opentripplanner.transit.model.site.RegularStopBuilder;
import org.opentripplanner.transit.model.site.Station;
public class StopModelBuilder {
private final AtomicInteger stopIndexCounter;
private final EntityById regularStopById = new DefaultEntityById<>();
private final EntityById areaStopById = new DefaultEntityById<>();
private final EntityById groupStopById = new DefaultEntityById<>();
private final EntityById stationById = new DefaultEntityById<>();
private final EntityById multiModalStationById = new DefaultEntityById<>();
private final EntityById groupOfStationById = new DefaultEntityById<>();
StopModelBuilder(AtomicInteger stopIndexCounter) {
this.stopIndexCounter = stopIndexCounter;
}
public ImmutableEntityById regularStopsById() {
return regularStopById;
}
public RegularStopBuilder regularStop(FeedScopedId id) {
return RegularStop.of(id, stopIndexCounter::getAndIncrement);
}
public RegularStop computeRegularStopIfAbsent(
FeedScopedId id,
Function factory
) {
return regularStopById.computeIfAbsent(id, factory);
}
public StopModelBuilder withRegularStop(RegularStop stop) {
regularStopById.add(stop);
return this;
}
public StopModelBuilder withRegularStops(Collection stops) {
regularStopById.addAll(stops);
return this;
}
public ImmutableEntityById stationById() {
return stationById;
}
public StopModelBuilder withStation(Station station) {
stationById.add(station);
return this;
}
public Station computeStationIfAbsent(FeedScopedId id, Function body) {
return stationById.computeIfAbsent(id, body::apply);
}
public StopModelBuilder withStations(Collection stations) {
stationById.addAll(stations);
return this;
}
public ImmutableEntityById multiModalStationById() {
return multiModalStationById;
}
public StopModelBuilder withMultiModalStation(MultiModalStation station) {
multiModalStationById.add(station);
return this;
}
public ImmutableEntityById groupOfStationById() {
return groupOfStationById;
}
public StopModelBuilder withGroupOfStation(GroupOfStations station) {
groupOfStationById.add(station);
return this;
}
public AreaStopBuilder areaStop(FeedScopedId id) {
return AreaStop.of(id, stopIndexCounter::getAndIncrement);
}
public ImmutableEntityById areaStopById() {
return areaStopById;
}
public StopModelBuilder withAreaStop(AreaStop stop) {
areaStopById.add(stop);
return this;
}
public StopModelBuilder withAreaStops(Collection stops) {
areaStopById.addAll(stops);
return this;
}
public GroupStopBuilder groupStop(FeedScopedId id) {
return GroupStop.of(id, stopIndexCounter::getAndIncrement);
}
public ImmutableEntityById groupStopById() {
return groupStopById;
}
public StopModelBuilder withGroupStop(GroupStop group) {
groupStopById.add(group);
return this;
}
public StopModelBuilder withGroupStops(Collection groups) {
groupStopById.addAll(groups);
return this;
}
/**
* Add the content of another stop model. There are no collision check, entities in the given
* {@code other} model, will replace existing entities.
*/
public StopModelBuilder addAll(StopModel other) {
regularStopById.addAll(other.listRegularStops());
stationById.addAll(other.listStations());
multiModalStationById.addAll(other.listMultiModalStations());
groupOfStationById.addAll(other.listGroupOfStations());
areaStopById.addAll(other.listAreaStops());
groupStopById.addAll(other.listGroupStops());
return this;
}
public StopModel build() {
return new StopModel(this);
}
AtomicInteger stopIndexCounter() {
return stopIndexCounter;
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy