use of org.opentripplanner.routing.core.Fare.FareType in project OpenTripPlanner by opentripplanner.
the class DefaultFareServiceImpl method getCost.
@Override
public Fare getCost(GraphPath path) {
List<Ride> rides = createRides(path);
// If there are no rides, there's no fare.
if (rides.size() == 0) {
return null;
}
Fare fare = new Fare();
boolean hasFare = false;
for (Map.Entry<FareType, Collection<FareRuleSet>> kv : fareRulesPerType.entrySet()) {
FareType fareType = kv.getKey();
Collection<FareRuleSet> fareRules = kv.getValue();
// pick up a random currency from fareAttributes,
// we assume that all tickets use the same currency
Currency currency = null;
WrappedCurrency wrappedCurrency = null;
if (fareRules.size() > 0) {
currency = Currency.getInstance(fareRules.iterator().next().getFareAttribute().getCurrencyType());
wrappedCurrency = new WrappedCurrency(currency);
}
hasFare = populateFare(fare, currency, fareType, rides, fareRules);
}
return hasFare ? fare : null;
}
use of org.opentripplanner.routing.core.Fare.FareType in project OpenTripPlanner by opentripplanner.
the class AddingMultipleFareService method getCost.
@Override
public Fare getCost(GraphPath path) {
Fare fare = null;
for (FareService subService : subServices) {
Fare subFare = subService.getCost(path);
if (subFare == null) {
// No fare, next one please
continue;
}
if (fare == null) {
// Pick first defined fare
fare = new Fare(subFare);
} else {
// Merge subFare with existing fare
// Must use a temporary as we need to keep fare clean during the loop on FareType
Fare newFare = new Fare(fare);
for (FareType fareType : FareType.values()) {
Money cost = fare.getFare(fareType);
Money subCost = subFare.getFare(fareType);
if (cost == null && subCost == null) {
continue;
}
if (cost != null && subCost == null) {
/*
* If for a given fare type we have partial data, we try to pickup the
* default "regular" cost to fill-in the missing information. For example,
* adding a bike fare which define only a "regular" cost, with some transit
* fare defining both "regular" and "student" costs. In that case, we
* probably want the "regular" bike fare to be added to the "student"
* transit fare too. Here we assume "regular" as a sane default value.
*/
subCost = subFare.getFare(FareType.regular);
} else if (cost == null && subCost != null) {
/* Same, but the other way around. */
cost = fare.getFare(FareType.regular);
}
if (cost != null && subCost != null) {
// Add sub cost to cost
newFare.addFare(fareType, cost.getCurrency(), cost.getCents() + subCost.getCents());
} else if (cost == null && subCost != null) {
// Add new cost
// Note: this should not happen often: only if a fare
// did not compute a "regular" fare.
newFare.addFare(fareType, subCost.getCurrency(), subCost.getCents());
}
}
fare = newFare;
}
}
// Can be null here if no sub-service has returned fare
return fare;
}
Aggregations