All Downloads are FREE. Search and download functionalities are using the official Maven repository.

org.opentripplanner.routing.algorithm.transferoptimization.model.TripToTripTransfer Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package org.opentripplanner.routing.algorithm.transferoptimization.model;

import javax.annotation.Nullable;
import org.opentripplanner.model.base.ToStringBuilder;
import org.opentripplanner.model.transfer.ConstrainedTransfer;
import org.opentripplanner.transit.raptor.api.transit.RaptorTransfer;
import org.opentripplanner.transit.raptor.api.transit.RaptorTripSchedule;

/**
 *
 * @param  The TripSchedule type defined by the user of the raptor API.
 */
public class TripToTripTransfer {

  private final TripStopTime from;
  private final TripStopTime to;
  private final RaptorTransfer pathTransfer;
  private final ConstrainedTransfer constrainedTransfer;

  public TripToTripTransfer(
      TripStopTime from,
      TripStopTime to,
      RaptorTransfer pathTransfer,
      @Nullable ConstrainedTransfer constrainedTransfer
  ) {
    this.from = from;
    this.to = to;
    this.pathTransfer = pathTransfer;
    this.constrainedTransfer = constrainedTransfer;
  }

  public TripStopTime from() {
    return from;
  }

  public TripStopTime to() {
    return to;
  }

  /**
   * The time it takes to transfer between the given from and to stop.
   * For a transfer at the same stop the time is zero.
   */
  public int transferDuration() {
    return sameStop() ? 0 : pathTransfer.durationInSeconds();
  }

  public int generalizedCost() {
    return sameStop() ? 0 : pathTransfer.generalizedCost();
  }

  public boolean sameStop() {
    return from.stop() == to.stop();
  }

  @Nullable
  public RaptorTransfer getPathTransfer() {
    return pathTransfer;
  }

  @Nullable
  public ConstrainedTransfer constrainedTransfer() {
    return constrainedTransfer;
  }

  @Override
  public String toString() {
    return ToStringBuilder.of(TripToTripTransfer.class)
            .addObj("from", from)
            .addObj("to", to)
            .addObj("transfer", pathTransfer)
            .toString();
  }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy