Skip to content

Commit

Permalink
GP-31 migrate java oop
Browse files Browse the repository at this point in the history
  • Loading branch information
shryhus committed Jan 5, 2021
1 parent fe92021 commit fd05d51
Show file tree
Hide file tree
Showing 7 changed files with 30 additions and 38 deletions.
8 changes: 0 additions & 8 deletions 2-0-data-structures-and-algorithms/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>com.bobocode</groupId>
<artifactId>java-fundamentals-util</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

<parent>
<groupId>com.bobocode</groupId>
Expand Down
8 changes: 0 additions & 8 deletions 3-0-java-core/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>com.bobocode</groupId>
<artifactId>java-fundamentals-util</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

<parent>
<groupId>com.bobocode</groupId>
Expand Down
8 changes: 0 additions & 8 deletions 4-0-object-oriented-programming/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,6 @@
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<dependencies>
<dependency>
<groupId>com.bobocode</groupId>
<artifactId>java-fundamentals-util</artifactId>
<version>1.0-SNAPSHOT</version>
<scope>compile</scope>
</dependency>
</dependencies>

<parent>
<groupId>com.bobocode</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
package com.bobocode.flight_search.data;

import com.bobocode.util.ExerciseNotCompletedException;
import com.bobocode.flight_search.service.Flights;

import java.util.HashSet;
import java.util.Set;
Expand All @@ -12,7 +12,7 @@
* todo: 1. Implement a method {@link FlightDao#register(String)} that store new flight number into the set
* todo: 2. Implement a method {@link FlightDao#findAll()} that returns a set of all flight numbers
*/
public class FlightDao {
public class FlightDao implements Flights {
private Set<String> flights = new HashSet<>();

/**
Expand All @@ -22,7 +22,7 @@ public class FlightDao {
* @return {@code true} if a flight number was stored, {@code false} otherwise
*/
public boolean register(String flightNumber) {
throw new ExerciseNotCompletedException();// todo: implement this method
return flights.add(flightNumber);
}

/**
Expand All @@ -31,7 +31,6 @@ public boolean register(String flightNumber) {
* @return a set of flight numbers
*/
public Set<String> findAll() {
throw new ExerciseNotCompletedException();// todo: implement this method
return flights;
}

}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
package com.bobocode.flight_search.factory;

import com.bobocode.flight_search.data.FlightDao;
import com.bobocode.flight_search.service.FlightService;
import com.bobocode.util.ExerciseNotCompletedException;

/**
* {@link FlightServiceFactory} is used to create an instance of {@link FlightService}
Expand All @@ -16,6 +16,7 @@ public class FlightServiceFactory {
* @return FlightService
*/
public FlightService creteFlightService() {
throw new ExerciseNotCompletedException();
return new FlightService(new FlightDao());
}
}

Original file line number Diff line number Diff line change
@@ -1,26 +1,31 @@
package com.bobocode.flight_search.service;

import com.bobocode.flight_search.data.FlightDao;
import com.bobocode.util.ExerciseNotCompletedException;

import java.util.List;

import static java.util.stream.Collectors.toList;

/**
* {@link FlightService} provides an API that allows to manage flight numbers
* <p>
* todo: 1. Using {@link FlightDao} implement method {@link FlightService#registerFlight(String)}
* todo: 2. Using {@link FlightDao} implement method {@link FlightService#searchFlights(String)}
* todo: 1. Using {@link com.bobocode.flight_search.data.FlightDao} implement method {@link FlightService#registerFlight(String)}
* todo: 2. Using {@link com.bobocode.flight_search.data.FlightDao} implement method {@link FlightService#searchFlights(String)}
*/
public class FlightService {

private Flights flights;

public FlightService(Flights flights) {
this.flights = flights;
}

/**
* Adds a new flight number
*
* @param flightNumber a flight number to add
* @return {@code true} if a flight number was added, {@code false} otherwise
*/
public boolean registerFlight(String flightNumber) {
throw new ExerciseNotCompletedException();
return flights.register(flightNumber);
}

/**
Expand All @@ -30,6 +35,8 @@ public boolean registerFlight(String flightNumber) {
* @return a list of found flight numbers
*/
public List<String> searchFlights(String query) {
throw new ExerciseNotCompletedException();
return flights.findAll().stream()
.filter(flightNum -> flightNum.toUpperCase().contains(query.toUpperCase()))
.collect(toList());
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package com.bobocode.flight_search.service;

import java.util.Set;

public interface Flights {
boolean register(String flightNumber);

Set<String> findAll();
}

0 comments on commit fd05d51

Please sign in to comment.