Skip to content

Commit

Permalink
Convert pricing config from array to key-value.
Browse files Browse the repository at this point in the history
  • Loading branch information
laurentg committed Mar 31, 2015
1 parent 6194442 commit 536e564
Showing 1 changed file with 6 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,9 @@ the License, or (at your option) any later version.
import java.util.Collections;
import java.util.Comparator;
import java.util.Currency;
import java.util.Iterator;
import java.util.List;
import java.util.Map;

import org.onebusaway.gtfs.services.GtfsRelationalDao;
import org.opentripplanner.common.model.P2;
Expand Down Expand Up @@ -62,9 +64,10 @@ public void configure(JsonNode config) {

// List of {time, price_cents}
pricingBySecond = new ArrayList<>();
for (JsonNode pConfig : config.path("prices")) {
int maxTimeSec = hmsToSeconds(pConfig.get("maxTime").asText());
int priceCent = pConfig.get("priceCents").asInt();
for (Iterator<Map.Entry<String, JsonNode>> i = config.path("prices").fields(); i.hasNext();) {
Map.Entry<String, JsonNode> kv = i.next();
int maxTimeSec = hmsToSeconds(kv.getKey());
int priceCent = (int) Math.round(kv.getValue().asDouble() * 100);
pricingBySecond.add(new P2<>(maxTimeSec, priceCent));
}
if (pricingBySecond.isEmpty())
Expand Down

0 comments on commit 536e564

Please sign in to comment.