Skip to content

Commit

Permalink
store fare details as array rather than list, addresses #2685
Browse files Browse the repository at this point in the history
  • Loading branch information
abyrd committed Jan 31, 2019
1 parent 2d53fbc commit ababea2
Showing 1 changed file with 9 additions and 5 deletions.
14 changes: 9 additions & 5 deletions src/main/java/org/opentripplanner/routing/core/Fare.java
Expand Up @@ -2,6 +2,7 @@


import java.io.Serializable; import java.io.Serializable;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.HashMap; import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
Expand All @@ -24,12 +25,15 @@ public static enum FareType implements Serializable {


/** /**
* A mapping from {@link FareType} to a list of {@link FareComponent}. * A mapping from {@link FareType} to a list of {@link FareComponent}.
* The FareComponents are stored in an array instead of a list because JAXB doesn't know how to deal with
* interfaces when serializing a trip planning response, and List is an interface.
* See https://stackoverflow.com/a/1119241/778449
*/ */
public HashMap<FareType, List<FareComponent>> details; public HashMap<FareType, FareComponent[]> details;


public Fare() { public Fare() {
fare = new HashMap<FareType, Money>(); fare = new HashMap<>();
details = new HashMap<FareType, List<FareComponent>>(); details = new HashMap<>();
} }


public Fare(Fare aFare) { public Fare(Fare aFare) {
Expand All @@ -51,15 +55,15 @@ public void addFare(FareType fareType, Money money) {
} }


public void addFareDetails(FareType fareType, List<FareComponent> newDetails) { public void addFareDetails(FareType fareType, List<FareComponent> newDetails) {
details.put(fareType, newDetails); details.put(fareType, newDetails.toArray(new FareComponent[newDetails.size()]));
} }


public Money getFare(FareType type) { public Money getFare(FareType type) {
return fare.get(type); return fare.get(type);
} }


public List<FareComponent> getDetails(FareType type) { public List<FareComponent> getDetails(FareType type) {
return details.get(type); return Arrays.asList(details.get(type));
} }


public void addCost(int surcharge) { public void addCost(int surcharge) {
Expand Down

0 comments on commit ababea2

Please sign in to comment.