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

Group 5: Refactoring #22

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
4 changes: 2 additions & 2 deletions src/main/java/flight/reservation/flight/Flight.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,13 +32,13 @@ private boolean isAircraftValid(Airport airport) {
return Arrays.stream(airport.getAllowedAircrafts()).anyMatch(x -> {
String model;
if (this.aircraft instanceof PassengerPlane) {
model = ((PassengerPlane) this.aircraft).model;
model = ((PassengerPlane) this.aircraft).getModel();
} else if (this.aircraft instanceof Helicopter) {
model = ((Helicopter) this.aircraft).getModel();
} else if (this.aircraft instanceof PassengerDrone) {
model = "HypaHype";
} else {
throw new IllegalArgumentException(String.format("Aircraft is not recognized"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this could be a separate commit

throw new IllegalArgumentException("Aircraft is not recognized");
}
return x.equals(model);
});
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/flight/reservation/flight/ScheduledFlight.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ public ScheduledFlight(int number, Airport departure, Airport arrival, Object ai

public int getCrewMemberCapacity() throws NoSuchFieldException {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i would keep the function but call the method of aircraft

if (this.aircraft instanceof PassengerPlane) {
return ((PassengerPlane) this.aircraft).crewCapacity;
return ((PassengerPlane) this.aircraft).getCrewCapacity();
}
if (this.aircraft instanceof Helicopter) {
return 2;
Expand All @@ -52,7 +52,7 @@ public void removePassengers(List<Passenger> passengers) {

public int getCapacity() throws NoSuchFieldException {
if (this.aircraft instanceof PassengerPlane) {
return ((PassengerPlane) this.aircraft).passengerCapacity;
return ((PassengerPlane) this.aircraft).getPassengerCapacity();
}
if (this.aircraft instanceof Helicopter) {
return ((Helicopter) this.aircraft).getPassengerCapacity();
Expand Down
12 changes: 1 addition & 11 deletions src/main/java/flight/reservation/plane/Helicopter.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,6 @@
package flight.reservation.plane;

public class Helicopter {
private final String model;
private final int passengerCapacity;
public class Helicopter extends IdentifiedFlightObject{

public Helicopter(String model) {
this.model = model;
Expand All @@ -14,12 +12,4 @@ public Helicopter(String model) {
throw new IllegalArgumentException(String.format("Model type '%s' is not recognized", model));
}
}

public String getModel() {
return model;
}

public int getPassengerCapacity() {
return passengerCapacity;
}
}
19 changes: 19 additions & 0 deletions src/main/java/flight/reservation/plane/IdentifiedFlightObject.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
package flight.reservation.plane;

public abstract class IdentifiedFlightObject {
String model;
int passengerCapacity;
int crewCapacity;

public String getModel() {
return model;
}

public int getPassengerCapacity() {
return passengerCapacity;
}

public int getCrewCapacity() {
return crewCapacity;
}
}
3 changes: 1 addition & 2 deletions src/main/java/flight/reservation/plane/PassengerDrone.java
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
package flight.reservation.plane;

public class PassengerDrone {
private final String model;
public class PassengerDrone extends IdentifiedFlightObject{

public PassengerDrone(String model) {
if (model.equals("HypaHype")) {
Expand Down
6 changes: 1 addition & 5 deletions src/main/java/flight/reservation/plane/PassengerPlane.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,6 @@
package flight.reservation.plane;

public class PassengerPlane {

public String model;
public int passengerCapacity;
public int crewCapacity;
public class PassengerPlane extends IdentifiedFlightObject{

public PassengerPlane(String model) {
this.model = model;
Expand Down