-
Notifications
You must be signed in to change notification settings - Fork 24
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 2: Aircraft Abstraction and Duplicate Code Removal. #20
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,7 @@ | ||
package flight.reservation.flight; | ||
|
||
import flight.reservation.Airport; | ||
import flight.reservation.plane.Helicopter; | ||
import flight.reservation.plane.PassengerDrone; | ||
import flight.reservation.plane.PassengerPlane; | ||
import flight.reservation.plane.IAircraft; | ||
|
||
import java.util.Arrays; | ||
|
||
|
@@ -12,9 +10,9 @@ public class Flight { | |
private int number; | ||
private Airport departure; | ||
private Airport arrival; | ||
protected Object aircraft; | ||
protected IAircraft aircraft; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good decision to remove object casting with base class |
||
|
||
public Flight(int number, Airport departure, Airport arrival, Object aircraft) throws IllegalArgumentException { | ||
public Flight(int number, Airport departure, Airport arrival, IAircraft aircraft) throws IllegalArgumentException { | ||
this.number = number; | ||
this.departure = departure; | ||
this.arrival = arrival; | ||
|
@@ -29,22 +27,12 @@ private void checkValidity() throws IllegalArgumentException { | |
} | ||
|
||
private boolean isAircraftValid(Airport airport) { | ||
return Arrays.stream(airport.getAllowedAircrafts()).anyMatch(x -> { | ||
String model; | ||
if (this.aircraft instanceof PassengerPlane) { | ||
model = ((PassengerPlane) this.aircraft).model; | ||
} 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")); | ||
} | ||
return x.equals(model); | ||
return Arrays.stream(airport.getAllowedAircrafts()).anyMatch(allowedModel -> { | ||
return allowedModel.equals(aircraft.getModel()); | ||
}); | ||
} | ||
|
||
public Object getAircraft() { | ||
public IAircraft getAircraft() { | ||
return aircraft; | ||
} | ||
|
||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package flight.reservation.plane; | ||
|
||
public class A350Plane implements IAircraft { | ||
|
||
@Override | ||
public String getModel() { | ||
return "A350"; | ||
} | ||
|
||
@Override | ||
public int getPassengerCapacity() { | ||
return 320; | ||
} | ||
|
||
@Override | ||
public int getCrewCapacity() { | ||
return 40; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package flight.reservation.plane; | ||
|
||
public class A380Plane implements IAircraft { | ||
|
||
@Override | ||
public String getModel() { | ||
return "A380"; | ||
} | ||
|
||
@Override | ||
public int getPassengerCapacity() { | ||
return 500; | ||
} | ||
|
||
@Override | ||
public int getCrewCapacity() { | ||
return 42; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package flight.reservation.plane; | ||
|
||
public class AntonovAN2Plane implements IAircraft { | ||
|
||
@Override | ||
public String getModel() { | ||
return "Antonov AN2"; | ||
} | ||
|
||
@Override | ||
public int getPassengerCapacity() { | ||
return 15; | ||
} | ||
|
||
@Override | ||
public int getCrewCapacity() { | ||
return 3; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package flight.reservation.plane; | ||
|
||
public class Embraer190Plane implements IAircraft { | ||
|
||
@Override | ||
public String getModel() { | ||
return "Embraer 190"; | ||
} | ||
|
||
@Override | ||
public int getPassengerCapacity() { | ||
return 25; | ||
} | ||
|
||
@Override | ||
public int getCrewCapacity() { | ||
return 5; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package flight.reservation.plane; | ||
|
||
public class H1Helicopter extends Helicopter { | ||
|
||
@Override | ||
public String getModel() { | ||
return "H1"; | ||
} | ||
|
||
@Override | ||
public int getPassengerCapacity() { | ||
return 4; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,14 @@ | ||
package flight.reservation.plane; | ||
|
||
public class H2Helicopter extends Helicopter { | ||
|
||
@Override | ||
public String getModel() { | ||
return "H2"; | ||
} | ||
|
||
@Override | ||
public int getPassengerCapacity() { | ||
return 6; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,25 +1,6 @@ | ||
package flight.reservation.plane; | ||
|
||
public class Helicopter { | ||
private final String model; | ||
private final int passengerCapacity; | ||
|
||
public Helicopter(String model) { | ||
this.model = model; | ||
if (model.equals("H1")) { | ||
passengerCapacity = 4; | ||
} else if (model.equals("H2")) { | ||
passengerCapacity = 6; | ||
} else { | ||
throw new IllegalArgumentException(String.format("Model type '%s' is not recognized", model)); | ||
} | ||
} | ||
|
||
public String getModel() { | ||
return model; | ||
} | ||
|
||
public int getPassengerCapacity() { | ||
return passengerCapacity; | ||
} | ||
public abstract class Helicopter implements IAircraft { | ||
liedtkeInTUM marked this conversation as resolved.
Show resolved
Hide resolved
|
||
@Override | ||
public int getCrewCapacity() { return 2; } | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think it is not ideal to enforce each helicopter with 2 crew member (although this setup allows it) |
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package flight.reservation.plane; | ||
|
||
public class HypaHypePassengerDrone implements IAircraft { | ||
|
||
@Override | ||
public String getModel() { | ||
return "HypyHype"; | ||
} | ||
|
||
|
||
@Override | ||
public int getPassengerCapacity() { | ||
return 4; | ||
} | ||
|
||
@Override | ||
public int getCrewCapacity() { | ||
return 0; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package flight.reservation.plane; | ||
|
||
public interface IAircraft { | ||
String getModel(); | ||
int getPassengerCapacity(); | ||
int getCrewCapacity(); | ||
} |
This file was deleted.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good decision to remove logic that belongs to a specific order