org.opentripplanner.transit.raptor.rangeraptor.debug.DebugHandlerFactory 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.rangeraptor.debug;
import org.opentripplanner.transit.raptor.api.path.Path;
import org.opentripplanner.transit.raptor.api.request.DebugRequest;
import org.opentripplanner.transit.raptor.api.transit.RaptorTripSchedule;
import org.opentripplanner.transit.raptor.api.view.ArrivalView;
import org.opentripplanner.transit.raptor.rangeraptor.WorkerLifeCycle;
import org.opentripplanner.transit.raptor.rangeraptor.view.DebugHandler;
import org.opentripplanner.transit.raptor.util.paretoset.ParetoSetEventListener;
/**
* Use this factory to create debug handlers. If a routing request has not enabled debugging
* {@code null} is returned. Use the {@link #isDebugStopArrival(int)} like methods before
* retrieving a handler.
*
* @param The TripSchedule type defined by the user of the raptor API.
*/
public class DebugHandlerFactory {
private DebugHandler> stopHandler;
private DebugHandler> pathHandler;
public DebugHandlerFactory(DebugRequest request, WorkerLifeCycle lifeCycle) {
this.stopHandler = isDebug(request.stopArrivalListener())
? new DebugHandlerStopArrivalAdapter<>(request, lifeCycle)
: null;
this.pathHandler = isDebug(request.pathFilteringListener())
? new DebugHandlerPathAdapter<>(request, lifeCycle)
: null;
}
/* Stop Arrival */
public boolean isDebugStopArrival() {
return stopHandler != null;
}
public boolean isDebugStopArrival(int stop) {
return stopHandler != null && stopHandler.isDebug(stop);
}
public DebugHandler> debugStopArrival() {
return stopHandler;
}
public ParetoSetEventListener> paretoSetStopArrivalListener(int stop) {
return isDebugStopArrival(stop) ? new ParetoSetDebugHandlerAdapter<>(stopHandler) : null;
}
/* path */
@SuppressWarnings("WeakerAccess")
public boolean isDebugPath() {
return pathHandler != null;
}
public ParetoSetDebugHandlerAdapter> paretoSetDebugPathListener() {
return isDebugPath() ? new ParetoSetDebugHandlerAdapter<>(pathHandler) : null;
}
/* private methods */
private boolean isDebug(Object handler) {
return handler != null;
}
}