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

org.opentripplanner.transit.raptor.api.path.TransferPathLeg Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package org.opentripplanner.transit.raptor.api.path;

import java.util.Objects;
import org.opentripplanner.transit.raptor.api.transit.RaptorTransfer;
import org.opentripplanner.transit.raptor.api.transit.RaptorTripSchedule;

/**
 * Represent a transfer leg in a path.
 *
 * @param  The TripSchedule type defined by the user of the raptor API.
 */
public final class TransferPathLeg implements PathLeg {

    private final int fromStop;
    private final int fromTime;
    private final int toStop;
    private final int toTime;
    private final int cost;
    private final RaptorTransfer transfer;
    private final PathLeg next;


    public TransferPathLeg(
            int fromStop,
            int fromTime,
            int toTime,
            int generalizedCost,
            RaptorTransfer transfer,
            PathLeg next
    ) {
        this.fromStop = fromStop;
        this.fromTime = fromTime;
        this.toStop = transfer.stop();
        this.toTime = toTime;
        this.cost = generalizedCost;
        this.transfer = transfer;
        this.next = next;
    }

    public RaptorTransfer transfer() {
        return transfer;
    }

    @Override
    public boolean isTransferLeg() {
        return true;
    }

    @Override
    public int fromStop() {
        return fromStop;
    }

    @Override
    public int fromTime() {
        return fromTime;
    }

    @Override
    public int toStop(){
        return toStop;
    }

    @Override
    public int toTime(){
        return toTime;
    }

    @Override
    public int generalizedCost() {
        return cost;
    }

    @Override
    public PathLeg nextLeg() {
        return next;
    }

    @Override
    public String toString() {
        return "Walk " + asString(toStop());
    }

    @Override
    public boolean equals(Object o) {
        if (this == o) { return true; }
        if (o == null || getClass() != o.getClass()) { return false; }
        TransferPathLeg that = (TransferPathLeg) o;
        return toStop == that.toStop &&
                toTime == that.toTime &&
                fromStop == that.fromStop &&
                fromTime == that.fromTime &&
                Objects.equals(next, that.next);
    }

    @Override
    public int hashCode() {
        return Objects.hash(toStop, toTime, fromStop, fromTime, next);
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy