Skip to content

Commit

Permalink
refactor(route request parameter): make JourneyRequest properties imm…
Browse files Browse the repository at this point in the history
…utable

Issue: opentripplanner#6048
  • Loading branch information
tobsesHub committed Oct 8, 2024
1 parent ce798fd commit 57011ac
Showing 1 changed file with 34 additions and 18 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,33 @@
// TODO VIA: Javadoc
public class JourneyRequest implements Cloneable, Serializable {

private TransitRequest transit = new TransitRequest();
private StreetRequest access = new StreetRequest();
private StreetRequest egress = new StreetRequest();
private StreetRequest transfer = new StreetRequest();
private StreetRequest direct = new StreetRequest();
private final TransitRequest transit;
private final StreetRequest access;
private final StreetRequest egress;
private final StreetRequest transfer;
private final StreetRequest direct;

public JourneyRequest() {
this.transit = new TransitRequest();
this.access = new StreetRequest();
this.egress = new StreetRequest();
this.transfer = new StreetRequest();
this.direct = new StreetRequest();
}

public JourneyRequest(
TransitRequest transit,
StreetRequest access,
StreetRequest egress,
StreetRequest transfer,
StreetRequest direct
) {
this.transit = transit;
this.access = access;
this.egress = egress;
this.transfer = transfer;
this.direct = direct;
}

public TransitRequest transit() {
return transit;
Expand Down Expand Up @@ -50,18 +72,12 @@ public RequestModes modes() {
}

public JourneyRequest clone() {
try {
var clone = (JourneyRequest) super.clone();
clone.transit = this.transit.clone();
clone.access = this.access.clone();
clone.egress = this.egress.clone();
clone.transfer = this.transfer.clone();
clone.direct = this.direct.clone();

return clone;
} catch (CloneNotSupportedException e) {
/* this will never happen since our super is the cloneable object */
throw new RuntimeException(e);
}
return new JourneyRequest(
this.transit.clone(),
this.access.clone(),
this.egress.clone(),
this.transfer.clone(),
this.direct.clone()
);
}
}

0 comments on commit 57011ac

Please sign in to comment.