Skip to content

Commit fd05d51

Browse files
committed
GP-31 migrate java oop
1 parent fe92021 commit fd05d51

File tree

7 files changed

+30
-38
lines changed

7 files changed

+30
-38
lines changed

2-0-data-structures-and-algorithms/pom.xml

-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
6-
<dependencies>
7-
<dependency>
8-
<groupId>com.bobocode</groupId>
9-
<artifactId>java-fundamentals-util</artifactId>
10-
<version>1.0-SNAPSHOT</version>
11-
<scope>compile</scope>
12-
</dependency>
13-
</dependencies>
146

157
<parent>
168
<groupId>com.bobocode</groupId>

3-0-java-core/pom.xml

-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
6-
<dependencies>
7-
<dependency>
8-
<groupId>com.bobocode</groupId>
9-
<artifactId>java-fundamentals-util</artifactId>
10-
<version>1.0-SNAPSHOT</version>
11-
<scope>compile</scope>
12-
</dependency>
13-
</dependencies>
146

157
<parent>
168
<groupId>com.bobocode</groupId>

4-0-object-oriented-programming/pom.xml

-8
Original file line numberDiff line numberDiff line change
@@ -3,14 +3,6 @@
33
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
44
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
55
<modelVersion>4.0.0</modelVersion>
6-
<dependencies>
7-
<dependency>
8-
<groupId>com.bobocode</groupId>
9-
<artifactId>java-fundamentals-util</artifactId>
10-
<version>1.0-SNAPSHOT</version>
11-
<scope>compile</scope>
12-
</dependency>
13-
</dependencies>
146

157
<parent>
168
<groupId>com.bobocode</groupId>

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,26 +1,31 @@
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>
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)}
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)