-
Notifications
You must be signed in to change notification settings - Fork 0
/
AdministrationServiceImpl.java
57 lines (54 loc) · 1.91 KB
/
AdministrationServiceImpl.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
import java.rmi.RemoteException;
import java.rmi.server.UnicastRemoteObject;
import java.util.ArrayList;
import java.util.Iterator;
import java.util.List;
public class AdministrationServiceImpl extends UnicastRemoteObject implements AdministrationService {
private List<Flight> flights;
private List<Airport> airports;
protected AdministrationServiceImpl() throws RemoteException {
super();
flights = new ArrayList<>();
airports = new ArrayList<>();
}
//Done.
@Override
public void addFlight(Flight flight) throws RemoteException {
flights.add(flight);
System.out.println("Flight added: " + flight.getCode());
}
//Done.
@Override
public void removeFlight(String flightId) throws RemoteException {
Iterator<Flight> iterator = flights.iterator();
while (iterator.hasNext()) {
Flight flight = iterator.next();
if (flight.getCode().equals(flightId)) {
iterator.remove();
System.out.println("Flight removed: " + flight.getCode());
return;
}
}
System.out.println("Flight with ID " + flightId + " not found.");
}
//Done.
@Override
public void addAirport(Airport airport) throws RemoteException {
airports.add(airport);
System.out.println("Airport added: " + airport.getCode());
}
//Done.
@Override
public void removeAirport(String airportId) throws RemoteException {
Iterator<Airport> iterator = airports.iterator();
while (iterator.hasNext()) {
Airport airport = iterator.next();
if (airport.getCode().equals(airportId)) {
iterator.remove();
System.out.println("Airport removed: " + airport.getCode());
return;
}
}
System.out.println("Airport with ID " + airportId + " not found.");
}
}