-
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 5: Refactoring #22
Open
j-gassner
wants to merge
4
commits into
fortiss-cce:master
Choose a base branch
from
j-gassner:master
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from 3 commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
ba51dd7
Implement class hierarchy for aircrafts
j-gassner 00c647d
Replace use of Object with IdentifiedFlightObject
j-gassner 6d03879
Remove getCapacity() from ScheduledFlight as it was redundant with ge…
j-gassner 57ac6cc
Forgot to tick the box to commit my pair programming partner's change…
j-gassner File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -3,6 +3,7 @@ | |
import flight.reservation.Airport; | ||
import flight.reservation.Passenger; | ||
import flight.reservation.plane.Helicopter; | ||
import flight.reservation.plane.IdentifiedFlightObject; | ||
import flight.reservation.plane.PassengerDrone; | ||
import flight.reservation.plane.PassengerPlane; | ||
|
||
|
@@ -16,13 +17,13 @@ public class ScheduledFlight extends Flight { | |
private final Date departureTime; | ||
private double currentPrice = 100; | ||
|
||
public ScheduledFlight(int number, Airport departure, Airport arrival, Object aircraft, Date departureTime) { | ||
public ScheduledFlight(int number, Airport departure, Airport arrival, IdentifiedFlightObject aircraft, Date departureTime) { | ||
super(number, departure, arrival, aircraft); | ||
this.departureTime = departureTime; | ||
this.passengers = new ArrayList<>(); | ||
} | ||
|
||
public ScheduledFlight(int number, Airport departure, Airport arrival, Object aircraft, Date departureTime, double currentPrice) { | ||
public ScheduledFlight(int number, Airport departure, Airport arrival, IdentifiedFlightObject aircraft, Date departureTime, double currentPrice) { | ||
super(number, departure, arrival, aircraft); | ||
this.departureTime = departureTime; | ||
this.passengers = new ArrayList<>(); | ||
|
@@ -31,7 +32,7 @@ public ScheduledFlight(int number, Airport departure, Airport arrival, Object ai | |
|
||
public int getCrewMemberCapacity() throws NoSuchFieldException { | ||
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 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; | ||
|
@@ -52,7 +53,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(); | ||
|
@@ -64,7 +65,7 @@ public int getCapacity() throws NoSuchFieldException { | |
} | ||
|
||
public int getAvailableCapacity() throws NoSuchFieldException { | ||
return this.getCapacity() - this.passengers.size(); | ||
return this.aircraft.getPassengerCapacity() - this.passengers.size(); | ||
} | ||
|
||
public Date getDepartureTime() { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
19 changes: 19 additions & 0 deletions
19
src/main/java/flight/reservation/plane/IdentifiedFlightObject.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -96,7 +96,7 @@ void thenTheBookingShouldBeStopped() throws NoSuchFieldException { | |
ScheduledFlight scheduledFlight = schedule.searchScheduledFlight(flight.getNumber()); | ||
assertThrows(IllegalStateException.class, () -> customer.createOrder(Arrays.asList("Amanda", "Max"), Arrays.asList(scheduledFlight), 180)); | ||
assertEquals(3, scheduledFlight.getPassengers().size()); | ||
assertEquals(4, scheduledFlight.getCapacity()); | ||
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. after the presentation today, I would prefer the old solution here :) |
||
assertEquals(4, scheduledFlight.getAircraft().getPassengerCapacity()); | ||
assertEquals(1, scheduledFlight.getAvailableCapacity()); | ||
assertTrue(scheduledFlight.getPassengers().stream().noneMatch(passenger -> passenger.getName().equals("Max"))); | ||
assertTrue(scheduledFlight.getPassengers().stream().noneMatch(passenger -> passenger.getName().equals("Amanda"))); | ||
|
@@ -113,7 +113,7 @@ void thenTheBookingShouldSucceed() throws NoSuchFieldException { | |
FlightOrder order = customer.createOrder(Arrays.asList("Amanda", "Max"), Arrays.asList(scheduledFlight), 180); | ||
|
||
assertEquals(2, scheduledFlight.getPassengers().size()); | ||
assertEquals(4, scheduledFlight.getCapacity()); | ||
assertEquals(4, scheduledFlight.getAircraft().getPassengerCapacity()); | ||
assertEquals(2, scheduledFlight.getAvailableCapacity()); | ||
assertTrue(scheduledFlight.getPassengers().stream().anyMatch(passenger -> passenger.getName().equals("Max"))); | ||
assertTrue(scheduledFlight.getPassengers().stream().anyMatch(passenger -> passenger.getName().equals("Amanda"))); | ||
|
@@ -207,7 +207,7 @@ void thenTheBookingShouldSucceed() throws NoSuchFieldException { | |
assertEquals(900, creditCard.getAmount()); | ||
assertEquals(1, scheduledFlight.getPassengers().size()); | ||
assertEquals("Max", scheduledFlight.getPassengers().get(0).getName()); | ||
assertEquals(500, scheduledFlight.getCapacity()); | ||
assertEquals(500, scheduledFlight.getAircraft().getPassengerCapacity()); | ||
assertEquals(499, scheduledFlight.getAvailableCapacity()); | ||
|
||
} | ||
|
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
this could be a separate commit