1
1
package com .bobocode .flight_search .service ;
2
2
3
- import com .bobocode .flight_search .data .FlightDao ;
4
- import com .bobocode .util .ExerciseNotCompletedException ;
5
-
6
3
import java .util .List ;
7
4
5
+ import static java .util .stream .Collectors .toList ;
6
+
8
7
/**
9
8
* {@link FlightService} provides an API that allows to manage flight numbers
10
9
* <p>
11
- * todo: 1. Using {@link FlightDao} implement method {@link FlightService#registerFlight(String)}
12
- * todo: 2. Using {@link FlightDao} implement method {@link FlightService#searchFlights(String)}
10
+ * todo: 1. Using {@link com.bobocode.flight_search.data. FlightDao} implement method {@link FlightService#registerFlight(String)}
11
+ * todo: 2. Using {@link com.bobocode.flight_search.data. FlightDao} implement method {@link FlightService#searchFlights(String)}
13
12
*/
14
13
public class FlightService {
15
14
15
+ private Flights flights ;
16
+
17
+ public FlightService (Flights flights ) {
18
+ this .flights = flights ;
19
+ }
20
+
16
21
/**
17
22
* Adds a new flight number
18
23
*
19
24
* @param flightNumber a flight number to add
20
25
* @return {@code true} if a flight number was added, {@code false} otherwise
21
26
*/
22
27
public boolean registerFlight (String flightNumber ) {
23
- throw new ExerciseNotCompletedException ( );
28
+ return flights . register ( flightNumber );
24
29
}
25
30
26
31
/**
@@ -30,6 +35,8 @@ public boolean registerFlight(String flightNumber) {
30
35
* @return a list of found flight numbers
31
36
*/
32
37
public List <String > searchFlights (String query ) {
33
- throw new ExerciseNotCompletedException ();
38
+ return flights .findAll ().stream ()
39
+ .filter (flightNum -> flightNum .toUpperCase ().contains (query .toUpperCase ()))
40
+ .collect (toList ());
34
41
}
35
42
}
0 commit comments