Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Refactor JourneyRequest to initialize by constructor #6126

Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@ -49,19 +71,14 @@ public RequestModes modes() {
.build();
}

@Override
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()
);
}
}
Loading