Databases Reference
In-Depth Information
1 publicclass Booking {
2
3 List<Flight>allInOneFlight= new ArrayList<>();
4 List<Flight>splittedInMultipleFlights= new ArrayList<>();
5
6 /**
7
*Booksaflightfromanairporttoanothergivenadeparture
andreturningdate
8 */
9 publicvoid bookFlight( int persons,Stringfrom,Stringto,
Datedeparture,Dateback){
Iterator<Airline>it=CompaniesRegistry.INSTANCE.
getCompanbiesIterator();
10
11
12
if (!it.hasNext()){
ErrorLogger.configurationError();
13
}
14
15
16
while (it.hasNext()){
Airlineairline=it.next();
17
processAirline(airLine);
18
}
19
20
21
if (allInOneFlight.size()>0){
SingleSolutionsolution=findBestSolution(
allInOneFlight);
22
reservationMaker.book(solution);
23
} else {
24
CompositeSolutionsolution=
findCompositeSolution(
splittedInMultipleFlights);
25
reservationMaker.book(solution);
26
}
27
28
29 }
30
31 /**
32 *Identifiestheavailableflightsforagivenairline
33 */
34 privatevoid processAirline(AirLineairLine, int persons,
Stringfrom,Stringto,Datedeparture,Dateback){
List<Flight>flights=airLine.getAvailableFlights(
persons,from,to,departure,back);
35
Iterator<Flight>it=flights.iterator();
36
while (it.hasNext()){
37
Flightflight=it.next();
38
39
40
if (flight.getAvailableSeats()>=persons){
allInOneFlight.add(flight);
41
} else {
42
splittedInMultipleFlights.add(flight);
43
}
44
}
45
46
47 }
48
49 }
Listing 2.1: An excerpt of the reserveFlight component.
 
Search WWH ::




Custom Search