|
|
@ -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); |
|
|
|
} |