org.opentripplanner.transit.raptor.api.request.DebugRequestBuilder 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
package org.opentripplanner.transit.raptor.api.request;
import org.opentripplanner.transit.raptor.api.debug.DebugEvent;
import org.opentripplanner.transit.raptor.api.debug.DebugLogger;
import org.opentripplanner.transit.raptor.api.path.Path;
import org.opentripplanner.transit.raptor.api.transit.RaptorTripSchedule;
import org.opentripplanner.transit.raptor.api.view.ArrivalView;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.function.Consumer;
/**
* Mutable version of {@link DebugRequest}.
*
* @param The TripSchedule type defined by the user of the raptor API.
*/
public class DebugRequestBuilder {
private final List stops = new ArrayList<>();
private final List path = new ArrayList<>();
private int debugPathFromStopIndex;
private Consumer>> stopArrivalListener;
private Consumer>> pathFilteringListener;
private DebugLogger logger;
DebugRequestBuilder(DebugRequest debug) {
this.stops.addAll(debug.stops());
this.path.addAll(debug.path());
this.debugPathFromStopIndex = debug.debugPathFromStopIndex();
this.stopArrivalListener = debug.stopArrivalListener();
this.pathFilteringListener = debug.pathFilteringListener();
this.logger = debug.logger();
}
public List stops() {
return stops;
}
public DebugRequestBuilder addStops(Collection stops) {
this.stops.addAll(stops);
return this;
}
public List path() {
return path;
}
public DebugRequestBuilder addPath(Collection path) {
if(!path.isEmpty()) {
throw new IllegalStateException("The API support only one debug path. Existing: " + this.path + ", new: " + path);
}
this.path.addAll(path);
return this;
}
public int debugPathFromStopIndex() {
return debugPathFromStopIndex;
}
public DebugRequestBuilder debugPathFromStopIndex(Integer debugPathStartAtStopIndex) {
this.debugPathFromStopIndex = debugPathStartAtStopIndex;
return this;
}
public Consumer>> stopArrivalListener() {
return stopArrivalListener;
}
public DebugRequestBuilder stopArrivalListener(Consumer>> stopArrivalListener) {
this.stopArrivalListener = stopArrivalListener;
return this;
}
public Consumer>> pathFilteringListener() {
return pathFilteringListener;
}
public DebugRequestBuilder pathFilteringListener(Consumer>> pathFilteringListener) {
this.pathFilteringListener = pathFilteringListener;
return this;
}
public DebugLogger logger() {
return logger;
}
public DebugRequestBuilder logger(DebugLogger logger) {
this.logger = logger;
return this;
}
public DebugRequestBuilder reverseDebugRequest() {
Collections.reverse(this.path);
return this;
}
public DebugRequest build() {
return new DebugRequest<>(this);
}
}