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

org.opentripplanner.ext.fares.impl.CombinedInterlinedTransitLeg Maven / Gradle / Ivy

There is a newer version: 2.6.0
Show newest version
package org.opentripplanner.ext.fares.impl;

import java.time.ZonedDateTime;
import java.util.List;
import java.util.Set;
import javax.annotation.Nonnull;
import org.locationtech.jts.geom.LineString;
import org.opentripplanner.model.plan.Place;
import org.opentripplanner.model.plan.StopArrival;
import org.opentripplanner.model.plan.TransitLeg;
import org.opentripplanner.transit.model.basic.TransitMode;
import org.opentripplanner.transit.model.network.Route;
import org.opentripplanner.transit.model.organization.Agency;
import org.opentripplanner.transit.model.site.FareZone;
import org.opentripplanner.transit.model.timetable.Trip;
import org.opentripplanner.util.lang.ListUtils;

/**
 * This is a fake leg that combines two interlined legs for the purpose of fare calculation.
 * 

* We pretend that two legs are a single one so that you will not be charged twice. */ class CombinedInterlinedTransitLeg implements TransitLeg { private final TransitLeg first; private final TransitLeg second; public CombinedInterlinedTransitLeg(TransitLeg first, TransitLeg second) { this.first = first; this.second = second; } public Agency getAgency() { return first.getAgency(); } @Nonnull @Override public TransitMode getMode() { return first.getMode(); } @Nonnull @Override public Route getRoute() { return first.getRoute(); } @Nonnull @Override public Trip getTrip() { return first.getTrip(); } @Override public ZonedDateTime getStartTime() { return first.getStartTime(); } @Override public ZonedDateTime getEndTime() { return second.getStartTime(); } @Override public double getDistanceMeters() { return first.getDistanceMeters() + second.getDistanceMeters(); } @Override public Place getFrom() { return first.getFrom(); } @Override public Place getTo() { return second.getTo(); } @Override public List getIntermediateStops() { return ListUtils.combine(first.getIntermediateStops(), second.getIntermediateStops()); } @Override public LineString getLegGeometry() { return null; } @Override public int getGeneralizedCost() { return first.getGeneralizedCost() + second.getGeneralizedCost(); } @Override public Set getFareZones() { Set fareZones = first.getFareZones(); fareZones.addAll(second.getFareZones()); return fareZones; } }





© 2015 - 2025 Weber Informatics LLC | Privacy Policy