diff --git a/src/main/java/hs/fulda/de/ci/exam/project/FlightReservationRepository.java b/src/main/java/hs/fulda/de/ci/exam/project/FlightReservationRepository.java index 5a1a071..c169649 100644 --- a/src/main/java/hs/fulda/de/ci/exam/project/FlightReservationRepository.java +++ b/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 flightReservationList = new ConcurrentHashMap(); + + 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 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 findAll(); - void save(FlightReservation flightReservation); }