You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
36 lines
1.2 KiB
36 lines
1.2 KiB
package hs.fulda.de.ci.exam.project;
|
|
|
|
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));
|
|
}
|
|
|
|
}
|