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

org.opentripplanner.routing.bike_rental.TimeBasedBikeRentalFareService Maven / Gradle / Ivy

There is a newer version: 2.5.0
Show newest version
package org.opentripplanner.routing.bike_rental;

import org.opentripplanner.transit.raptor.api.path.Path;
import org.opentripplanner.common.model.P2;
import org.opentripplanner.routing.algorithm.raptor.transit.TransitLayer;
import org.opentripplanner.routing.algorithm.raptor.transit.TripSchedule;
import org.opentripplanner.routing.core.Fare;
import org.opentripplanner.routing.core.Fare.FareType;
import org.opentripplanner.routing.core.WrappedCurrency;
import org.opentripplanner.routing.services.FareService;
import org.opentripplanner.transit.raptor.api.path.PathLeg;

import java.io.Serializable;
import java.util.Currency;
import java.util.List;

/**
 * This appears to be used in combination with transit using an AddingMultipleFareService.
 */
public class TimeBasedBikeRentalFareService implements FareService, Serializable {

    private static final long serialVersionUID = 5226621661906177942L;

    // Each entry is ; the list is sorted in
    // ascending time order
    private List> pricing_by_second;

    private Currency currency;

    protected TimeBasedBikeRentalFareService(Currency currency, List> pricingBySecond) {
        this.currency = currency;
        this.pricing_by_second = pricingBySecond;
    }

    // FIXME we need to test if the leg is a bike rental leg.
    //       OTP2 doesn't handle non walk access or egress yet.
    private int getLegCost(PathLeg pathLeg) {
        int rideCost = 0;
        int rideTime = pathLeg.duration();
        for (P2 bracket : pricing_by_second) {
            int time = bracket.first;
            if (rideTime < time) {
                rideCost = bracket.second;
                // FIXME this break seems to exit at the first matching bracket rather than the last.
                break;
            }
        }
        return rideCost;
    }

    @Override
    public Fare getCost(Path path, TransitLayer transitLayer) {

        int rideCost = getLegCost(path.accessLeg());
        rideCost += getLegCost(path.egressLeg());

        Fare fare = new Fare();
        fare.addFare(FareType.regular, new WrappedCurrency(currency), rideCost);
        return fare;
    }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy