File tree Expand file tree Collapse file tree 4 files changed +28
-12
lines changed
4-0-object-oriented-programming/src/main/java/com/bobocode/flight_search Expand file tree Collapse file tree 4 files changed +28
-12
lines changed Original file line number Diff line number Diff line change 11package com .bobocode .flight_search .data ;
22
3- import com .bobocode .util . ExerciseNotCompletedException ;
3+ import com .bobocode .flight_search . service . Flights ;
44
55import java .util .HashSet ;
66import java .util .Set ;
1212 * todo: 1. Implement a method {@link FlightDao#register(String)} that store new flight number into the set
1313 * todo: 2. Implement a method {@link FlightDao#findAll()} that returns a set of all flight numbers
1414 */
15- public class FlightDao {
15+ public class FlightDao implements Flights {
1616 private Set <String > flights = new HashSet <>();
1717
1818 /**
@@ -22,7 +22,7 @@ public class FlightDao {
2222 * @return {@code true} if a flight number was stored, {@code false} otherwise
2323 */
2424 public boolean register (String flightNumber ) {
25- throw new ExerciseNotCompletedException (); // todo: implement this method
25+ return flights . add ( flightNumber );
2626 }
2727
2828 /**
@@ -31,7 +31,6 @@ public boolean register(String flightNumber) {
3131 * @return a set of flight numbers
3232 */
3333 public Set <String > findAll () {
34- throw new ExerciseNotCompletedException (); // todo: implement this method
34+ return flights ;
3535 }
36-
3736}
Original file line number Diff line number Diff line change 11package com .bobocode .flight_search .factory ;
22
3+ import com .bobocode .flight_search .data .FlightDao ;
34import com .bobocode .flight_search .service .FlightService ;
4- import com .bobocode .util .ExerciseNotCompletedException ;
55
66/**
77 * {@link FlightServiceFactory} is used to create an instance of {@link FlightService}
@@ -16,6 +16,7 @@ public class FlightServiceFactory {
1616 * @return FlightService
1717 */
1818 public FlightService creteFlightService () {
19- throw new ExerciseNotCompletedException ( );
19+ return new FlightService ( new FlightDao () );
2020 }
2121}
22+
Original file line number Diff line number Diff line change 11package com .bobocode .flight_search .service ;
22
3- import com .bobocode .flight_search .data .FlightDao ;
4- import com .bobocode .util .ExerciseNotCompletedException ;
5-
63import java .util .List ;
74
5+ import static java .util .stream .Collectors .toList ;
6+
87/**
98 * {@link FlightService} provides an API that allows to manage flight numbers
109 * <p>
1312 */
1413public class FlightService {
1514
15+ private Flights flights ;
16+
17+ public FlightService (Flights flights ) {
18+ this .flights = flights ;
19+ }
20+
1621 /**
1722 * Adds a new flight number
1823 *
1924 * @param flightNumber a flight number to add
2025 * @return {@code true} if a flight number was added, {@code false} otherwise
2126 */
2227 public boolean registerFlight (String flightNumber ) {
23- throw new ExerciseNotCompletedException ( );
28+ return flights . register ( flightNumber );
2429 }
2530
2631 /**
@@ -30,6 +35,8 @@ public boolean registerFlight(String flightNumber) {
3035 * @return a list of found flight numbers
3136 */
3237 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 ());
3441 }
3542}
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