You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
84 lines
2.2 KiB
84 lines
2.2 KiB
package hs.fulda.de.ci.exam.project;
|
|
|
|
import java.util.HashSet;
|
|
|
|
import static hs.fulda.de.ci.exam.project.FlightStatus.Cancelled;
|
|
|
|
public class Flight {
|
|
String flightNumber;
|
|
Airport departure;
|
|
Airport arrival;
|
|
int durationInMinutes;
|
|
HashSet<FlightInstance> flightInstances = new HashSet<>();
|
|
|
|
public Flight(String flightNumber, Airport departure, Airport arrival, int durationInMinutes) {
|
|
this.flightNumber = flightNumber;
|
|
this.departure = departure;
|
|
this.arrival = arrival;
|
|
this.durationInMinutes = durationInMinutes;
|
|
}
|
|
|
|
public Flight() {
|
|
|
|
}
|
|
|
|
public HashSet<FlightInstance> getInstances() {
|
|
return this.flightInstances;
|
|
}
|
|
|
|
public FlightInstance getFlightInstance(FlightInstance fi) {
|
|
for (FlightInstance obj : flightInstances) {
|
|
if (obj.equals(fi))
|
|
return obj;
|
|
}
|
|
return null;
|
|
}
|
|
|
|
public boolean cancel(FlightInstance fInstance1) {
|
|
if (flightInstances.contains(fInstance1)) {
|
|
for (FlightInstance obj : flightInstances) {
|
|
if (obj.equals(fInstance1)) {
|
|
obj.status = Cancelled;
|
|
System.out.println("Flight intance is cancelled");
|
|
}
|
|
}
|
|
return true;
|
|
}
|
|
return false;
|
|
|
|
}
|
|
|
|
public boolean addFlightSchedule(FlightInstance fi) {
|
|
flightInstances.add(fi);
|
|
if (flightInstances.contains(fi)) {
|
|
System.out.println("Flight instance is added");
|
|
return true;
|
|
}
|
|
return false;
|
|
}
|
|
|
|
public String getFlightNumber() {
|
|
return flightNumber;
|
|
}
|
|
|
|
public Airport getDeparture() {
|
|
return departure;
|
|
}
|
|
|
|
public Airport getArrival() {
|
|
return arrival;
|
|
}
|
|
|
|
public int getDurationInMinutes() {
|
|
return durationInMinutes;
|
|
}
|
|
|
|
public void setFlightNumber(String flightNumber) {
|
|
this.flightNumber = flightNumber;
|
|
}
|
|
|
|
@Override
|
|
public String toString() {
|
|
return "Flight = {" + "flightNumber=" + flightNumber + '\'' + ", departure=" + departure + ", arrival='" + arrival + ", durationInMinutes=" + durationInMinutes + '}';
|
|
}
|
|
}
|