Browse Source

implemented flight reservation repository

feature-pr-PersonAndItinerary
Sona Markosyan 3 years ago
parent
commit
e4f7c68e2a
  1. 36
      src/main/java/hs/fulda/de/ci/exam/project/FlightReservationRepository.java

36
src/main/java/hs/fulda/de/ci/exam/project/FlightReservationRepository.java

@ -1,8 +1,36 @@
package hs.fulda.de.ci.exam.project;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
public class FlightReservationRepository {
Map<String, FlightReservation> flightReservationList = new ConcurrentHashMap<String, FlightReservation>();
public boolean checkIfFlightAlreadyExist(FlightReservation flightReservation){
if(flightReservationList.containsKey(generateKey(flightReservation))){
return true;
}
return false;
}
FlightReservation findById(String id){
FlightReservation flightReservation = flightReservationList.get(id);
return flightReservation;
}
private String generateKey(FlightReservation flightReservation) {
return String.format("%s", flightReservation.getReservationNumber());
}
public Collection<FlightReservation> findAll() {
return flightReservationList.values();
}
public boolean save(FlightReservation flightReservation){
flightReservationList.put(generateKey(flightReservation), flightReservation);
return true;
}
public void delete(FlightReservation flightReservation) {
flightReservationList.remove(generateKey(flightReservation));
}
public interface FlightReservationRepository {
ArrayList<FlightReservation> findAll();
void save(FlightReservation flightReservation);
}
Loading…
Cancel
Save