Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Gp 31 migrate java oop into exercise/completed #18

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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,10 +1,9 @@
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>
Expand All @@ -13,14 +12,20 @@
*/
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();
}