|
@@ -66,17 +66,13 @@ public class ParkingLotService {
|
|
|
|
|
|
|
|
//check if there is available slots
|
|
//check if there is available slots
|
|
|
Layout layout = getLayoutByNameOrThrow(carSlotItem.getType(), parkingLot);
|
|
Layout layout = getLayoutByNameOrThrow(carSlotItem.getType(), parkingLot);
|
|
|
- if(layout.getAvailable().get() == 0){
|
|
|
|
|
- throw new ParkingIsFullException("Parking lot is full for this type of car");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ isAvailableOrThrow(layout);
|
|
|
//found & available spot
|
|
//found & available spot
|
|
|
synchronized (this){
|
|
synchronized (this){
|
|
|
//double check locking
|
|
//double check locking
|
|
|
parkingLot = findParkingLotByIdOrThrow(parkingLotId);
|
|
parkingLot = findParkingLotByIdOrThrow(parkingLotId);
|
|
|
layout = getLayoutByNameOrThrow(carSlotItem.getType(), parkingLot);
|
|
layout = getLayoutByNameOrThrow(carSlotItem.getType(), parkingLot);
|
|
|
- if(layout.getAvailable().get() == 0){
|
|
|
|
|
- throw new ParkingIsFullException("Parking lot is full for this type of car");
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ isAvailableOrThrow(layout);
|
|
|
Long slotId = layout.decrementAndGetID();
|
|
Long slotId = layout.decrementAndGetID();
|
|
|
carSlotItem.setSlot(slotId);
|
|
carSlotItem.setSlot(slotId);
|
|
|
carSlotItem.setParkingLotId(parkingLotId);
|
|
carSlotItem.setParkingLotId(parkingLotId);
|
|
@@ -87,6 +83,11 @@ public class ParkingLotService {
|
|
|
return carSlotItem;
|
|
return carSlotItem;
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+ private void isAvailableOrThrow(Layout layout){
|
|
|
|
|
+ if(layout.getAvailable().get() == 0){
|
|
|
|
|
+ throw new ParkingIsFullException("Parking lot is full for this type of car");
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
|
|
|
public ParkingLot updateParkingLot(Long parkingLotId, ParkingLot parkingLotItem) {
|
|
public ParkingLot updateParkingLot(Long parkingLotId, ParkingLot parkingLotItem) {
|
|
|
//parking lot exists ?
|
|
//parking lot exists ?
|