Skip to content

Commit 787778d

Browse files
authored
Merge pull request #18 from bobocode-projects/GP-31_migrate_java_oop_into_exercise/completed
Gp 31 migrate java oop into exercise/completed
2 parents 54bdcc2 + 760dbfc commit 787778d

File tree

4 files changed

+28
-12
lines changed

4 files changed

+28
-12
lines changed

4-0-object-oriented-programming/src/main/java/com/bobocode/flight_search/data/FlightDao.java

+4-5
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
package com.bobocode.flight_search.data;
22

3-
import com.bobocode.util.ExerciseNotCompletedException;
3+
import com.bobocode.flight_search.service.Flights;
44

55
import java.util.HashSet;
66
import java.util.Set;
@@ -12,7 +12,7 @@
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
}

4-0-object-oriented-programming/src/main/java/com/bobocode/flight_search/factory/FlightServiceFactory.java

+3-2
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
package com.bobocode.flight_search.factory;
22

3+
import com.bobocode.flight_search.data.FlightDao;
34
import 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 numberDiff line numberDiff line change
@@ -1,10 +1,9 @@
11
package com.bobocode.flight_search.service;
22

3-
import com.bobocode.flight_search.data.FlightDao;
4-
import com.bobocode.util.ExerciseNotCompletedException;
5-
63
import 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>
@@ -13,14 +12,20 @@
1312
*/
1413
public 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 numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
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+
}

0 commit comments

Comments
 (0)