File tree 4 files changed +28
-12
lines changed
4-0-object-oriented-programming/src/main/java/com/bobocode/flight_search
4 files changed +28
-12
lines changed Original file line number Diff line number Diff line change 1
1
package com .bobocode .flight_search .data ;
2
2
3
- import com .bobocode .util . ExerciseNotCompletedException ;
3
+ import com .bobocode .flight_search . service . Flights ;
4
4
5
5
import java .util .HashSet ;
6
6
import java .util .Set ;
12
12
* todo: 1. Implement a method {@link FlightDao#register(String)} that store new flight number into the set
13
13
* todo: 2. Implement a method {@link FlightDao#findAll()} that returns a set of all flight numbers
14
14
*/
15
- public class FlightDao {
15
+ public class FlightDao implements Flights {
16
16
private Set <String > flights = new HashSet <>();
17
17
18
18
/**
@@ -22,7 +22,7 @@ public class FlightDao {
22
22
* @return {@code true} if a flight number was stored, {@code false} otherwise
23
23
*/
24
24
public boolean register (String flightNumber ) {
25
- throw new ExerciseNotCompletedException (); // todo: implement this method
25
+ return flights . add ( flightNumber );
26
26
}
27
27
28
28
/**
@@ -31,7 +31,6 @@ public boolean register(String flightNumber) {
31
31
* @return a set of flight numbers
32
32
*/
33
33
public Set <String > findAll () {
34
- throw new ExerciseNotCompletedException (); // todo: implement this method
34
+ return flights ;
35
35
}
36
-
37
36
}
Original file line number Diff line number Diff line change 1
1
package com .bobocode .flight_search .factory ;
2
2
3
+ import com .bobocode .flight_search .data .FlightDao ;
3
4
import com .bobocode .flight_search .service .FlightService ;
4
- import com .bobocode .util .ExerciseNotCompletedException ;
5
5
6
6
/**
7
7
* {@link FlightServiceFactory} is used to create an instance of {@link FlightService}
@@ -16,6 +16,7 @@ public class FlightServiceFactory {
16
16
* @return FlightService
17
17
*/
18
18
public FlightService creteFlightService () {
19
- throw new ExerciseNotCompletedException ( );
19
+ return new FlightService ( new FlightDao () );
20
20
}
21
21
}
22
+
Original file line number Diff line number Diff line change 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>
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
}
Original file line number Diff line number Diff line change
1
+ package com .bobocode .flight_search .service ;
2
+
3
+ import java .util .Set ;
4
+
5
+ public interface Flights {
6
+ boolean register (String flightNumber );
7
+
8
+ Set <String > findAll ();
9
+ }
You can’t perform that action at this time.
0 commit comments