private FareRule doMap(org.onebusaway.gtfs.model.FareRule rhs) { FareRule lhs = new FareRule(); lhs.setFare(fareAttributeMapper.map(rhs.getFare())); lhs.setRoute(routeMapper.map(rhs.getRoute())); lhs.setOriginId(rhs.getOriginId()); lhs.setDestinationId(rhs.getDestinationId()); lhs.setContainsId(rhs.getContainsId()); return lhs; } }
private void addNewFareRule(String orig, String dest, float price) { FareAttribute attr = getFareAttributeForCost(price); String origZone = getZoneForStopId(orig); String destZone = getZoneForStopId(dest); Pair<String> key = Tuples.pair(origZone, destZone); FareRule rule = newFareRules.get(key); if (rule != null) { if (rule.getFare().getId().equals(attr.getId())) { _log.debug("Fare rule already exists for stops {} -> {}, skipping", orig, dest); } else { throw new RuntimeException("Invalid fare matrix: stops with the same zone given different prices (zone " + origZone + ", " + destZone + ")"); } } rule = new FareRule(); rule.setFare(attr); rule.setRoute(route); rule.setOriginId(origZone); rule.setDestinationId(destZone); newFareRules.put(key, rule); }
@Override public void run(TransformContext context, GtfsMutableRelationalDao dao) { // remove rules for route for (FareRule rule : new HashSet<FareRule>(dao.getAllFareRules())) { if (rule.getRoute() != null && rule.getRoute().getId().getId().equals(routeId)) { if (!isExemplarSet()) { setAttributesFromExemplar(rule.getFare()); } route = rule.getRoute(); dao.removeEntity(rule); } } for (FareAttribute attr : new HashSet<FareAttribute>(dao.getAllFareAttributes())) { if (dao.getFareRulesForFareAttribute(attr).isEmpty()) { dao.removeEntity(attr); } } // add new rules FareCreationListener listener = new FareCreationListener(); listener.setDao(dao); try { URL url = new URL(csvUrl); try (InputStream is = url.openStream()) { new CSVLibrary().parse(is, listener); } } catch (Exception e) { e.printStackTrace(); } listener.flushNewFares(); }
@Override protected void replaceDuplicateEntry(GtfsMergeContext context, FareAttribute oldAttribute, FareAttribute newAttribute) { GtfsRelationalDao source = context.getSource(); for (FareRule fareRule : source.getFareRulesForFareAttribute(oldAttribute)) { fareRule.setFare(newAttribute); } } }
@Override protected void replaceDuplicateEntry(GtfsMergeContext context, FareAttribute oldAttribute, FareAttribute newAttribute) { GtfsRelationalDao source = context.getSource(); for (FareRule fareRule : source.getFareRulesForFareAttribute(oldAttribute)) { fareRule.setFare(newAttribute); } } }
@Override protected boolean entitiesAreIdentical(FareRule fareRuleA, FareRule fareRuleB) { if (!fareRuleA.getFare().equals(fareRuleB.getFare())) { return false; } if (!equals(fareRuleA.getRoute(), fareRuleB.getRoute())) { return false; } if (!equals(fareRuleA.getOriginId(), fareRuleB.getOriginId())) { return false; } if (!equals(fareRuleA.getDestinationId(), fareRuleB.getDestinationId())) { return false; } if (!equals(fareRuleA.getContainsId(), fareRuleB.getContainsId())) { return false; } return true; }
@Override protected boolean entitiesAreIdentical(FareRule fareRuleA, FareRule fareRuleB) { if (!fareRuleA.getFare().equals(fareRuleB.getFare())) { return false; } if (!equals(fareRuleA.getRoute(), fareRuleB.getRoute())) { return false; } if (!equals(fareRuleA.getOriginId(), fareRuleB.getOriginId())) { return false; } if (!equals(fareRuleA.getDestinationId(), fareRuleB.getDestinationId())) { return false; } if (!equals(fareRuleA.getContainsId(), fareRuleB.getContainsId())) { return false; } return true; }
Collection<FareRule> rules = getDao().getAllFareRules(); for (FareRule rule: rules) { FareAttribute fare = rule.getFare(); AgencyAndId id = fare.getId(); FareRuleSet fareRule = fareRules.get(id); fareRules.put(id, fareRule); String contains = rule.getContainsId(); if (contains != null) { fareRule.addContains(contains); String origin = rule.getOriginId(); String destination = rule.getDestinationId(); if (origin != null || destination != null) { fareRule.addOriginDestination(origin, destination); Route route = rule.getRoute(); if (route != null) { AgencyAndId routeId = route.getId();