diff --git a/LowLevelDesign/ParkingLot/.idea/.gitignore b/LowLevelDesign/ParkingLot/.idea/.gitignore new file mode 100644 index 0000000..26d3352 --- /dev/null +++ b/LowLevelDesign/ParkingLot/.idea/.gitignore @@ -0,0 +1,3 @@ +# Default ignored files +/shelf/ +/workspace.xml diff --git a/LowLevelDesign/ParkingLot/.idea/misc.xml b/LowLevelDesign/ParkingLot/.idea/misc.xml new file mode 100644 index 0000000..e0844bc --- /dev/null +++ b/LowLevelDesign/ParkingLot/.idea/misc.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LowLevelDesign/ParkingLot/.idea/modules.xml b/LowLevelDesign/ParkingLot/.idea/modules.xml new file mode 100644 index 0000000..5db11fd --- /dev/null +++ b/LowLevelDesign/ParkingLot/.idea/modules.xml @@ -0,0 +1,8 @@ + + + + + + + + \ No newline at end of file diff --git a/LowLevelDesign/ParkingLot/.idea/uiDesigner.xml b/LowLevelDesign/ParkingLot/.idea/uiDesigner.xml new file mode 100644 index 0000000..2b63946 --- /dev/null +++ b/LowLevelDesign/ParkingLot/.idea/uiDesigner.xml @@ -0,0 +1,124 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/LowLevelDesign/ParkingLot/.idea/vcs.xml b/LowLevelDesign/ParkingLot/.idea/vcs.xml new file mode 100644 index 0000000..b2bdec2 --- /dev/null +++ b/LowLevelDesign/ParkingLot/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/LowLevelDesign/ParkingLot/ParkingLot.iml b/LowLevelDesign/ParkingLot/ParkingLot.iml new file mode 100644 index 0000000..c90834f --- /dev/null +++ b/LowLevelDesign/ParkingLot/ParkingLot.iml @@ -0,0 +1,11 @@ + + + + + + + + + + + \ No newline at end of file diff --git a/LowLevelDesign/ParkingLot/README.md b/LowLevelDesign/ParkingLot/README.md new file mode 100644 index 0000000..bcc5af9 --- /dev/null +++ b/LowLevelDesign/ParkingLot/README.md @@ -0,0 +1,12 @@ +# Parking Lot Design +## Problem Statement +You own a parking lot of tech center where multiple company offices are co-located. You've design a parking space management system so as different companies cars/bikes can be parked in allocated slots. The employee of specific company should collect a ticket on entrance(if parking space is available) and pay the amount on exit from parking space. + +## System Requirements +#### Vehicle Type +1. Two wheeler - bikes +2. Four wheeler - cars + +#### Levels on parking space +The parking space can have multiple floors/levels + diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/ParkingLotApplication.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/ParkingLotApplication.class new file mode 100644 index 0000000..18ba000 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/ParkingLotApplication.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/exception/NonRetryableException.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/exception/NonRetryableException.class new file mode 100644 index 0000000..aa231c1 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/exception/NonRetryableException.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/exception/RetryableException.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/exception/RetryableException.class new file mode 100644 index 0000000..a737d30 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/exception/RetryableException.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/gate/EntranceGate.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/gate/EntranceGate.class new file mode 100644 index 0000000..06aea8a Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/gate/EntranceGate.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/gate/ExitGate.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/gate/ExitGate.class new file mode 100644 index 0000000..14a9e72 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/gate/ExitGate.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/gate/ParkingGate.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/gate/ParkingGate.class new file mode 100644 index 0000000..f575d80 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/gate/ParkingGate.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parking/ParkingFloor.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parking/ParkingFloor.class new file mode 100644 index 0000000..c165ed2 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parking/ParkingFloor.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parking/ParkingFloorNumber.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parking/ParkingFloorNumber.class new file mode 100644 index 0000000..be79221 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parking/ParkingFloorNumber.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parking/ParkingLot.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parking/ParkingLot.class new file mode 100644 index 0000000..7e83c57 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parking/ParkingLot.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parking/ParkingSpot.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parking/ParkingSpot.class new file mode 100644 index 0000000..402acb8 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parking/ParkingSpot.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parking/ParkingSpotType.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parking/ParkingSpotType.class new file mode 100644 index 0000000..f797b34 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parking/ParkingSpotType.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parkingticket/ParkingTicket.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parkingticket/ParkingTicket.class new file mode 100644 index 0000000..772fa64 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parkingticket/ParkingTicket.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parkingticket/ParkingTicketStatus.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parkingticket/ParkingTicketStatus.class new file mode 100644 index 0000000..04793dd Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/parkingticket/ParkingTicketStatus.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/Amount.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/Amount.class new file mode 100644 index 0000000..6225228 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/Amount.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/CardPayment.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/CardPayment.class new file mode 100644 index 0000000..38a0340 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/CardPayment.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/CashPayment.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/CashPayment.class new file mode 100644 index 0000000..ae2fd8f Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/CashPayment.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/CurrencyType.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/CurrencyType.class new file mode 100644 index 0000000..81dcd52 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/CurrencyType.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/Payment.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/Payment.class new file mode 100644 index 0000000..9ee0c97 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/Payment.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/PaymentStatus.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/PaymentStatus.class new file mode 100644 index 0000000..9f8983f Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/PaymentStatus.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/PaymentType.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/PaymentType.class new file mode 100644 index 0000000..446d59c Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/payment/PaymentType.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/vehicle/Bike.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/vehicle/Bike.class new file mode 100644 index 0000000..aa90e16 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/vehicle/Bike.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/vehicle/Car.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/vehicle/Car.class new file mode 100644 index 0000000..fa34525 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/vehicle/Car.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/vehicle/Vehicle.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/vehicle/Vehicle.class new file mode 100644 index 0000000..1526c07 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/vehicle/Vehicle.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/vehicle/VehicleType.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/vehicle/VehicleType.class new file mode 100644 index 0000000..d889dba Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/model/vehicle/VehicleType.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/ParkingLotService.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/ParkingLotService.class new file mode 100644 index 0000000..f2278c5 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/ParkingLotService.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/impl/ParkingLotServiceImpl.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/impl/ParkingLotServiceImpl.class new file mode 100644 index 0000000..c052bb1 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/impl/ParkingLotServiceImpl.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/parking/ParkingService.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/parking/ParkingService.class new file mode 100644 index 0000000..c7a0928 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/parking/ParkingService.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/parking/impl/ParkingServiceImpl.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/parking/impl/ParkingServiceImpl.class new file mode 100644 index 0000000..7823a14 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/parking/impl/ParkingServiceImpl.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/ticket/TicketService.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/ticket/TicketService.class new file mode 100644 index 0000000..a4a98bd Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/ticket/TicketService.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/ticket/impl/TicketServiceImpl.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/ticket/impl/TicketServiceImpl.class new file mode 100644 index 0000000..a3aaf23 Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/service/ticket/impl/TicketServiceImpl.class differ diff --git a/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/utility/ParkingUtility.class b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/utility/ParkingUtility.class new file mode 100644 index 0000000..f66bf1f Binary files /dev/null and b/LowLevelDesign/ParkingLot/out/production/ParkingLot/com/msdeepsingh/parkinglot/utility/ParkingUtility.class differ diff --git a/LowLevelDesign/ParkingLot/src/ParkingLotApplication.java b/LowLevelDesign/ParkingLot/src/ParkingLotApplication.java new file mode 100644 index 0000000..c14909b --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/ParkingLotApplication.java @@ -0,0 +1,60 @@ +import com.msdeepsingh.parkinglot.model.gate.EntranceGate; +import com.msdeepsingh.parkinglot.model.gate.ExitGate; +import com.msdeepsingh.parkinglot.model.parking.*; +import com.msdeepsingh.parkinglot.model.parkingticket.ParkingTicket; +import com.msdeepsingh.parkinglot.model.vehicle.Vehicle; +import com.msdeepsingh.parkinglot.model.vehicle.VehicleType; +import com.msdeepsingh.parkinglot.service.impl.ParkingLotServiceImpl; +import com.msdeepsingh.parkinglot.service.ticket.impl.TicketServiceImpl; +import com.msdeepsingh.parkinglot.utility.ParkingUtility; + +import java.util.HashMap; +import java.util.Map; +import java.util.UUID; + +public class ParkingLotApplication { + public static void main(String[] args) { + System.out.println("Welcome to Parking Lot!"); + + ParkingLot parkingLot = ParkingLot.getParkingLot(); + + ParkingLotServiceImpl parkingLotService = new ParkingLotServiceImpl(parkingLot); + TicketServiceImpl ticketService = new TicketServiceImpl(); + + //create parking spots + Map parkingSpotMap = new HashMap<>(); + parkingSpotMap.put(1L, parkingLotService.addParkingSpot(ParkingUtility.createParkingSpot(1L, ParkingSpotType.FOUR_WHEELER), ParkingFloorNumber.GROUND)); + parkingSpotMap.put(3L, parkingLotService.addParkingSpot(ParkingUtility.createParkingSpot(2L, ParkingSpotType.TWO_WHEELER), ParkingFloorNumber.GROUND)); + parkingSpotMap.put(4L, parkingLotService.addParkingSpot(ParkingUtility.createParkingSpot(3L, ParkingSpotType.FOUR_WHEELER), ParkingFloorNumber.GROUND)); + parkingSpotMap.put(5L, parkingLotService.addParkingSpot(ParkingUtility.createParkingSpot(4L, ParkingSpotType.TWO_WHEELER), ParkingFloorNumber.GROUND)); + + //create entry and entrance gate for ground floor + EntranceGate entranceGate = new EntranceGate(1L, ParkingFloorNumber.GROUND, true); + ExitGate exitGate = new ExitGate(2L, ParkingFloorNumber.GROUND, true); + Map entranceGateMap = new HashMap<>(); + entranceGateMap.put(1L, entranceGate); + + Map exitGateMap = new HashMap<>(); + exitGateMap.put(2L, exitGate); + + + //create Parking Floors + Map parkingFloorMap = new HashMap<>(); + ParkingFloor groundParkingFloor = new ParkingFloor(ParkingFloorNumber.GROUND, parkingSpotMap, entranceGateMap, exitGateMap); + parkingFloorMap.put(ParkingFloorNumber.GROUND, groundParkingFloor); + + //Initialize parking Lot with name identifier and parking floors information + parkingLot.setParkingLotId(UUID.randomUUID().toString()); + parkingLot.setParkingLotName("Mandeep ka parking lot"); + parkingLot.setParkingFloorMap(parkingFloorMap); + + //create vehicle + Vehicle myHondaCar = new Vehicle("binaNumberWaliGadi", VehicleType.CAR); + Vehicle myHeroWaliMotorCycle = new Vehicle("127.0.0.1", VehicleType.BIKE); + + //getParkingTicket + ParkingTicket carTicket = ticketService.getParkingTicket(myHondaCar, 1L); + System.out.println("Ticket generated successfully for vehicle: "+myHondaCar.getVehicleNo()); + System.out.println("Ticket Details: "+carTicket); + } +} \ No newline at end of file diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/exception/NonRetryableException.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/exception/NonRetryableException.java new file mode 100644 index 0000000..def23aa --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/exception/NonRetryableException.java @@ -0,0 +1,17 @@ +package com.msdeepsingh.parkinglot.exception; + +public class NonRetryableException extends RuntimeException { + private String message; + + public NonRetryableException(String message) { + this.message = message; + } + + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/exception/RetryableException.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/exception/RetryableException.java new file mode 100644 index 0000000..2230db0 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/exception/RetryableException.java @@ -0,0 +1,18 @@ +package com.msdeepsingh.parkinglot.exception; + +public class RetryableException extends RuntimeException { + private String message; + + public RetryableException(String message) { + this.message = message; + } + + @Override + public String getMessage() { + return message; + } + + public void setMessage(String message) { + this.message = message; + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/gate/EntranceGate.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/gate/EntranceGate.java new file mode 100644 index 0000000..0b95e15 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/gate/EntranceGate.java @@ -0,0 +1,10 @@ +package com.msdeepsingh.parkinglot.model.gate; + +import com.msdeepsingh.parkinglot.model.parking.ParkingFloorNumber; + +public class EntranceGate extends ParkingGate { + + public EntranceGate(long gateNo, ParkingFloorNumber floorNo, boolean isOpen) { + super(gateNo, floorNo, isOpen); + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/gate/ExitGate.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/gate/ExitGate.java new file mode 100644 index 0000000..4d08036 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/gate/ExitGate.java @@ -0,0 +1,10 @@ +package com.msdeepsingh.parkinglot.model.gate; + +import com.msdeepsingh.parkinglot.model.parking.ParkingFloorNumber; + +public class ExitGate extends ParkingGate { + + public ExitGate(long gateNo, ParkingFloorNumber floorNo, boolean isOpen) { + super(gateNo, floorNo, isOpen); + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/gate/ParkingGate.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/gate/ParkingGate.java new file mode 100644 index 0000000..26408a5 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/gate/ParkingGate.java @@ -0,0 +1,42 @@ +package com.msdeepsingh.parkinglot.model.gate; + +import com.msdeepsingh.parkinglot.model.parking.ParkingFloorNumber; + +public abstract class ParkingGate { + /** + * For unique representation of gates across the floor, the gate numbers are not repeated. + * */ + private long gateNo; + private ParkingFloorNumber floorNo; + private boolean isOpen; + + public ParkingGate(long gateNo, ParkingFloorNumber floorNo, boolean isOpen) { + this.gateNo = gateNo; + this.floorNo = floorNo; + this.isOpen = isOpen; + } + + public long getGateNo() { + return gateNo; + } + + public void setGateNo(long gateNo) { + this.gateNo = gateNo; + } + + public ParkingFloorNumber getFloorNo() { + return floorNo; + } + + public void setFloorNo(ParkingFloorNumber floorNo) { + this.floorNo = floorNo; + } + + public boolean isOpen() { + return isOpen; + } + + public void setOpen(boolean open) { + isOpen = open; + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parking/ParkingFloor.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parking/ParkingFloor.java new file mode 100644 index 0000000..d812892 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parking/ParkingFloor.java @@ -0,0 +1,64 @@ +package com.msdeepsingh.parkinglot.model.parking; + +import com.msdeepsingh.parkinglot.model.gate.EntranceGate; +import com.msdeepsingh.parkinglot.model.gate.ExitGate; + +import java.util.Map; + +public class ParkingFloor { + private ParkingFloorNumber floorNo; + private Map parkingSpotMap; + private Map entranceGateMap; + private Map exitGateMap; + + public ParkingFloor(ParkingFloorNumber floorNo, Map parkingSpotMap, + Map entranceGateMap, + Map exitGateMap) { + this.floorNo = floorNo; + this.parkingSpotMap = parkingSpotMap; + this.entranceGateMap = entranceGateMap; + this.exitGateMap = exitGateMap; + } + + public ParkingFloorNumber getFloorNo() { + return floorNo; + } + + public void setFloorNo(ParkingFloorNumber floorNo) { + this.floorNo = floorNo; + } + + public Map getParkingSpotMap() { + return parkingSpotMap; + } + + public void setParkingSpotMap(Map parkingSpotMap) { + this.parkingSpotMap = parkingSpotMap; + } + + public Map getEntranceGateMap() { + return entranceGateMap; + } + + public void setEntranceGateMap(Map entranceGateMap) { + this.entranceGateMap = entranceGateMap; + } + + public Map getExitGateMap() { + return exitGateMap; + } + + public void setExitGateMap(Map exitGateMap) { + this.exitGateMap = exitGateMap; + } + + @Override + public String toString() { + return "ParkingFloor{" + + "floorNo=" + floorNo + + ", parkingSpotMap=" + parkingSpotMap + + ", entranceGateMap=" + entranceGateMap + + ", exitGateMap=" + exitGateMap + + '}'; + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parking/ParkingFloorNumber.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parking/ParkingFloorNumber.java new file mode 100644 index 0000000..67a2de4 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parking/ParkingFloorNumber.java @@ -0,0 +1,10 @@ +package com.msdeepsingh.parkinglot.model.parking; + +/** + * Available floors in parkingLot. + * */ +public enum ParkingFloorNumber { + GROUND, + FIRST, + SECOND; +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parking/ParkingLot.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parking/ParkingLot.java new file mode 100644 index 0000000..822cdf2 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parking/ParkingLot.java @@ -0,0 +1,65 @@ +package com.msdeepsingh.parkinglot.model.parking; + +import java.util.Map; +import java.util.Objects; + +/** + * System Hierarchy ---> + * Complete parking area is represented by {@link ParkingLot}; + * {@link ParkingLot} constitutes multiple {@link ParkingFloor}; + * {@link ParkingFloor} constitutes multiple {@link ParkingSpot}. + * */ +public class ParkingLot { + private Map parkingFloorMap; + /** + * Same system may be running on multiple parking lot locations, + * parkingSpaceId will uniquely identify {@link ParkingLot} + * + * more params can be added such as Address as per requirement. + * */ + private String parkingLotId; + private String parkingLotName; + + + private static ParkingLot parkingLot = null; + + /** + * Private Constructor to ensure Singleton behavior. + * */ + private ParkingLot() { + //get information from database to load + //Example - parking floor, parking spots, entrance/exit gates + //current status of parkingLot - booked/available slots + } + + public static ParkingLot getParkingLot() { + if(Objects.isNull(parkingLot)) { + parkingLot = new ParkingLot(); + } + return parkingLot; + } + + public Map getParkingFloorMap() { + return parkingFloorMap; + } + + public void setParkingFloorMap(Map parkingFloorMap) { + this.parkingFloorMap = parkingFloorMap; + } + + public String getParkingLotId() { + return parkingLotId; + } + + public void setParkingLotId(String parkingLotId) { + this.parkingLotId = parkingLotId; + } + + public String getParkingLotName() { + return parkingLotName; + } + + public void setParkingLotName(String parkingLotName) { + this.parkingLotName = parkingLotName; + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parking/ParkingSpot.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parking/ParkingSpot.java new file mode 100644 index 0000000..a119d2c --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parking/ParkingSpot.java @@ -0,0 +1,72 @@ +package com.msdeepsingh.parkinglot.model.parking; + +import com.msdeepsingh.parkinglot.model.vehicle.Vehicle; +import com.msdeepsingh.parkinglot.model.vehicle.VehicleType; + +public class ParkingSpot { + private long spotNo; + private Vehicle vehicle; + /** + * VehicleType is added here so as system is extensible in a way that two-wheelers can also be parked + * at four wheeler parking space --> extended system requirement + * */ + private VehicleType vehicleType; + private ParkingSpotType parkingSpotType; + private boolean isFree; + + /** + * Creates default ParkingSpot with availability=true + * */ + public ParkingSpot(long spotNo, ParkingSpotType parkingSpotType) { + this.spotNo = spotNo; + this.parkingSpotType = parkingSpotType; + this.isFree = true; + } + public ParkingSpot(long spotNo, Vehicle vehicle, VehicleType vehicleType, ParkingSpotType parkingSpotType, boolean isFree) { + this.spotNo = spotNo; + this.vehicle = vehicle; + this.vehicleType = vehicleType; + this.parkingSpotType = parkingSpotType; + this.isFree = isFree; + } + + public long getSpotNo() { + return spotNo; + } + + public void setSpotNo(long spotNo) { + this.spotNo = spotNo; + } + + public Vehicle getVehicle() { + return vehicle; + } + + public void setVehicle(Vehicle vehicle) { + this.vehicle = vehicle; + } + + public VehicleType getVehicleType() { + return vehicleType; + } + + public void setVehicleType(VehicleType vehicleType) { + this.vehicleType = vehicleType; + } + + public ParkingSpotType getParkingSpotType() { + return parkingSpotType; + } + + public void setParkingSpotType(ParkingSpotType parkingSpotType) { + this.parkingSpotType = parkingSpotType; + } + + public boolean isFree() { + return isFree; + } + + public void setFree(boolean free) { + isFree = free; + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parking/ParkingSpotType.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parking/ParkingSpotType.java new file mode 100644 index 0000000..88b4ff4 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parking/ParkingSpotType.java @@ -0,0 +1,6 @@ +package com.msdeepsingh.parkinglot.model.parking; + +public enum ParkingSpotType { + TWO_WHEELER, + FOUR_WHEELER; +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parkingticket/ParkingTicket.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parkingticket/ParkingTicket.java new file mode 100644 index 0000000..af48366 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parkingticket/ParkingTicket.java @@ -0,0 +1,84 @@ +package com.msdeepsingh.parkinglot.model.parkingticket; + +import com.msdeepsingh.parkinglot.model.parking.ParkingSpot; +import com.msdeepsingh.parkinglot.model.payment.Payment; +import com.msdeepsingh.parkinglot.model.vehicle.Vehicle; + +public class ParkingTicket { + private long token; + private Vehicle vehicle; + private long entryTime; + private long entryGateNumber; + private ParkingSpot parkingSpot; + private Payment payment; + + public ParkingTicket(long token, Vehicle vehicle, long entryTime, long entryGateNumber, + ParkingSpot parkingSpot, Payment payment) { + this.token = token; + this.vehicle = vehicle; + this.entryTime = entryTime; + this.entryGateNumber = entryGateNumber; + this.parkingSpot = parkingSpot; + this.payment = payment; + } + + public long getToken() { + return token; + } + + public void setToken(long token) { + this.token = token; + } + + public Vehicle getVehicle() { + return vehicle; + } + + public void setVehicle(Vehicle vehicle) { + this.vehicle = vehicle; + } + + public long getEntryTime() { + return entryTime; + } + + public void setEntryTime(long entryTime) { + this.entryTime = entryTime; + } + + public long getEntryGateNumber() { + return entryGateNumber; + } + + public void setEntryGateNumber(long entryGateNumber) { + this.entryGateNumber = entryGateNumber; + } + + public ParkingSpot getParkingSpot() { + return parkingSpot; + } + + public void setParkingSpot(ParkingSpot parkingSpot) { + this.parkingSpot = parkingSpot; + } + + public Payment getTicketStatus() { + return payment; + } + + public void setTicketStatus(Payment payment) { + this.payment = payment; + } + + @Override + public String toString() { + return "ParkingTicket{" + + "token=" + token + + ", vehicle=" + vehicle + + ", entryTime=" + entryTime + + ", entryGateNumber=" + entryGateNumber + + ", parkingSpot=" + parkingSpot + + ", payment=" + payment + + '}'; + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parkingticket/ParkingTicketStatus.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parkingticket/ParkingTicketStatus.java new file mode 100644 index 0000000..260127e --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/parkingticket/ParkingTicketStatus.java @@ -0,0 +1,9 @@ +package com.msdeepsingh.parkinglot.model.parkingticket; + +/** +* ParkingTicketStatus is derived value from {@link com.msdeepsingh.parkinglot.model.payment.PaymentStatus} +* */ +public enum ParkingTicketStatus { + PAYMENT_PENDING, + PAYMENT_COMPLETED; +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/Amount.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/Amount.java new file mode 100644 index 0000000..37fce0d --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/Amount.java @@ -0,0 +1,6 @@ +package com.msdeepsingh.parkinglot.model.payment; + +public class Amount { + private Double value; + private CurrencyType currencyType; +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/CardPayment.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/CardPayment.java new file mode 100644 index 0000000..2348eb2 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/CardPayment.java @@ -0,0 +1,7 @@ +package com.msdeepsingh.parkinglot.model.payment; + +public class CardPayment extends Payment { + public CardPayment() { + super(PaymentType.CARD); + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/CashPayment.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/CashPayment.java new file mode 100644 index 0000000..e0f895c --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/CashPayment.java @@ -0,0 +1,7 @@ +package com.msdeepsingh.parkinglot.model.payment; + +public class CashPayment extends Payment { + public CashPayment() { + super(PaymentType.CASH); + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/CurrencyType.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/CurrencyType.java new file mode 100644 index 0000000..d9c2d86 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/CurrencyType.java @@ -0,0 +1,6 @@ +package com.msdeepsingh.parkinglot.model.payment; + +public enum CurrencyType { + USD, + INR; +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/Payment.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/Payment.java new file mode 100644 index 0000000..5898272 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/Payment.java @@ -0,0 +1,13 @@ +package com.msdeepsingh.parkinglot.model.payment; + +public class Payment { + //time in epoch + private long paymentDate; + private Amount amount; + private PaymentStatus paymentStatus; + private PaymentType paymentType; + + public Payment(PaymentType paymentType) { + this.paymentType = paymentType; + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/PaymentStatus.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/PaymentStatus.java new file mode 100644 index 0000000..4d6b28e --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/PaymentStatus.java @@ -0,0 +1,7 @@ +package com.msdeepsingh.parkinglot.model.payment; + +public enum PaymentStatus { + SUCCESS, + FAILED, + PENDING; +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/PaymentType.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/PaymentType.java new file mode 100644 index 0000000..e8ee108 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/payment/PaymentType.java @@ -0,0 +1,6 @@ +package com.msdeepsingh.parkinglot.model.payment; + +public enum PaymentType { + CASH, + CARD; +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/vehicle/Bike.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/vehicle/Bike.java new file mode 100644 index 0000000..f837c38 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/vehicle/Bike.java @@ -0,0 +1,10 @@ +package com.msdeepsingh.parkinglot.model.vehicle; + +/** + * Two-wheeler + * */ +public class Bike extends Vehicle { + public Bike(String vehicleNo) { + super(vehicleNo, VehicleType.BIKE); + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/vehicle/Car.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/vehicle/Car.java new file mode 100644 index 0000000..f74f496 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/vehicle/Car.java @@ -0,0 +1,10 @@ +package com.msdeepsingh.parkinglot.model.vehicle; + +/** + * Four Wheeler + * */ +public class Car extends Vehicle { + public Car(String vehicleNo) { + super(vehicleNo, VehicleType.CAR); + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/vehicle/Vehicle.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/vehicle/Vehicle.java new file mode 100644 index 0000000..f34d99f --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/vehicle/Vehicle.java @@ -0,0 +1,38 @@ +package com.msdeepsingh.parkinglot.model.vehicle; + +public class Vehicle { + private String vehicleNo; + private VehicleType vehicleType; + + public Vehicle(String vehicleNo, VehicleType vehicleType) { + this.vehicleNo = vehicleNo; + this.vehicleType = vehicleType; + } + + /** + * Use IntelliJ auto-generate functionality for getter/setter/toString() methods. + * */ + public String getVehicleNo() { + return vehicleNo; + } + + public VehicleType getVehicleType() { + return vehicleType; + } + + public void setVehicleNo(String vehicleNo) { + this.vehicleNo = vehicleNo; + } + + public void setVehicleType(VehicleType vehicleType) { + this.vehicleType = vehicleType; + } + + @Override + public String toString() { + return "Vehicle{" + + "vehicleNo='" + vehicleNo + '\'' + + ", vehicleType=" + vehicleType + + '}'; + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/vehicle/VehicleType.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/vehicle/VehicleType.java new file mode 100644 index 0000000..08ce654 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/model/vehicle/VehicleType.java @@ -0,0 +1,8 @@ +package com.msdeepsingh.parkinglot.model.vehicle; + +public enum VehicleType { + //Four wheeler vehicles + CAR, + // Two wheeler vehicles + BIKE; +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/ParkingLotService.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/ParkingLotService.java new file mode 100644 index 0000000..8e8d605 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/ParkingLotService.java @@ -0,0 +1,23 @@ +package com.msdeepsingh.parkinglot.service; + +import com.msdeepsingh.parkinglot.model.gate.EntranceGate; +import com.msdeepsingh.parkinglot.model.gate.ExitGate; +import com.msdeepsingh.parkinglot.model.parking.ParkingFloor; +import com.msdeepsingh.parkinglot.model.parking.ParkingFloorNumber; +import com.msdeepsingh.parkinglot.model.parking.ParkingSpot; + +/** + * Interface expose functions for basic utility of ParkingLot Application to setup infrastructure for + * application working. + * like setting up ParkingFloor/gates/parkingSpots. + * */ +public interface ParkingLotService { + ParkingSpot addParkingSpot(ParkingSpot parkingSpot, ParkingFloorNumber floorNo); + void removeParkingSpot(long spotNumber); // return nothing on success, exception on failure + ParkingFloor addParkingFloor(ParkingFloor parkingFloor); + void removeParkingFloor(ParkingFloorNumber floorNo); + EntranceGate addEntranceGate(ParkingFloorNumber floorNo, long gateNo); + void removeEntranceGate(ParkingFloorNumber floorNo, long gateNo); + ExitGate addExitGate(ParkingFloorNumber floorNo, long gateNo); + void removeExitGate(ParkingFloorNumber floorNo, long gateNo); +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/impl/ParkingLotServiceImpl.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/impl/ParkingLotServiceImpl.java new file mode 100644 index 0000000..cb58dbb --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/impl/ParkingLotServiceImpl.java @@ -0,0 +1,77 @@ +package com.msdeepsingh.parkinglot.service.impl; + +import com.msdeepsingh.parkinglot.exception.NonRetryableException; +import com.msdeepsingh.parkinglot.model.gate.EntranceGate; +import com.msdeepsingh.parkinglot.model.gate.ExitGate; +import com.msdeepsingh.parkinglot.model.parking.ParkingFloor; +import com.msdeepsingh.parkinglot.model.parking.ParkingFloorNumber; +import com.msdeepsingh.parkinglot.model.parking.ParkingLot; +import com.msdeepsingh.parkinglot.model.parking.ParkingSpot; +import com.msdeepsingh.parkinglot.service.ParkingLotService; + +import java.util.*; + +public class ParkingLotServiceImpl implements ParkingLotService { + ParkingLot parkingLot; + + public ParkingLotServiceImpl(ParkingLot parkingLot) { + this.parkingLot = parkingLot; + } + @Override + public ParkingSpot addParkingSpot(ParkingSpot parkingSpot, ParkingFloorNumber floorNo) { + Map parkingSpotMap; + if(Objects.isNull(parkingLot.getParkingFloorMap()) || Objects.isNull(parkingLot.getParkingFloorMap().get(floorNo)) + || Objects.isNull(parkingLot.getParkingFloorMap().get(floorNo).getParkingSpotMap())) { + parkingSpotMap = new HashMap<>(); + } else { + parkingSpotMap = parkingLot.getParkingFloorMap().get(floorNo).getParkingSpotMap(); + } + if(parkingSpotMap.containsKey(parkingSpot.getSpotNo())) { + throw new NonRetryableException(parkingSpot.getSpotNo() + + " is already present in parkingLot, please assign new spot number"); + } + parkingSpotMap.put(parkingSpot.getSpotNo(), parkingSpot); + return parkingSpot; + } + + @Override + public void removeParkingSpot(long spotNumber) { + + } + + @Override + public ParkingFloor addParkingFloor(ParkingFloor parkingFloor) { + Map parkingFloorMap = parkingLot.getParkingFloorMap(); + if(Objects.isNull(parkingFloorMap)) { + parkingFloorMap = new HashMap<>(); + } + parkingFloorMap.put(ParkingFloorNumber.GROUND, parkingFloor); + parkingLot.setParkingFloorMap(parkingFloorMap); + return parkingFloor; + } + + @Override + public void removeParkingFloor(ParkingFloorNumber floorNo) { + + } + + @Override + public EntranceGate addEntranceGate(ParkingFloorNumber floorNo, long gateNo) { + return new EntranceGate(gateNo, floorNo, true); + } + + @Override + public void removeEntranceGate(ParkingFloorNumber floorNo, long gateNo) { + + } + + @Override + public ExitGate addExitGate(ParkingFloorNumber floorNo, long gateNo) { + return new ExitGate(gateNo, floorNo, true); + } + + @Override + public void removeExitGate(ParkingFloorNumber floorNo, long gateNo) { + + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/parking/ParkingService.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/parking/ParkingService.java new file mode 100644 index 0000000..26b34a5 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/parking/ParkingService.java @@ -0,0 +1,8 @@ +package com.msdeepsingh.parkinglot.service.parking; + +import com.msdeepsingh.parkinglot.model.parkingticket.ParkingTicket; +import com.msdeepsingh.parkinglot.model.vehicle.Vehicle; + +public interface ParkingService { + ParkingTicket parkVehicle(long entryGateNo, Vehicle vehicle); +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/parking/impl/ParkingServiceImpl.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/parking/impl/ParkingServiceImpl.java new file mode 100644 index 0000000..0b9b531 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/parking/impl/ParkingServiceImpl.java @@ -0,0 +1,16 @@ +package com.msdeepsingh.parkinglot.service.parking.impl; + +import com.msdeepsingh.parkinglot.model.parkingticket.ParkingTicket; +import com.msdeepsingh.parkinglot.model.vehicle.Vehicle; +import com.msdeepsingh.parkinglot.service.parking.ParkingService; + +public class ParkingServiceImpl implements ParkingService { + @Override + public ParkingTicket parkVehicle(long entryGateNo, Vehicle vehicle) { + //find available slot via entryGateNo + //assign the slot to vehicle + //Generate Ticket with Payment PENDING + //mark slot as filled. + return null; + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/ticket/TicketService.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/ticket/TicketService.java new file mode 100644 index 0000000..c218254 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/ticket/TicketService.java @@ -0,0 +1,11 @@ +package com.msdeepsingh.parkinglot.service.ticket; + +import com.msdeepsingh.parkinglot.model.parkingticket.ParkingTicket; +import com.msdeepsingh.parkinglot.model.parkingticket.ParkingTicketStatus; +import com.msdeepsingh.parkinglot.model.vehicle.Vehicle; + +public interface TicketService { + public ParkingTicket getParkingTicket(Vehicle vehicle, long entryGateNo); + public ParkingTicketStatus getParkingTicketStatus(); + public Double getParkingAmount(); +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/ticket/impl/TicketServiceImpl.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/ticket/impl/TicketServiceImpl.java new file mode 100644 index 0000000..6402068 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/service/ticket/impl/TicketServiceImpl.java @@ -0,0 +1,24 @@ +package com.msdeepsingh.parkinglot.service.ticket.impl; + +import com.msdeepsingh.parkinglot.model.parkingticket.ParkingTicket; +import com.msdeepsingh.parkinglot.model.parkingticket.ParkingTicketStatus; +import com.msdeepsingh.parkinglot.model.vehicle.Vehicle; +import com.msdeepsingh.parkinglot.service.ticket.TicketService; + +public class TicketServiceImpl implements TicketService { + @Override + public ParkingTicket getParkingTicket(Vehicle vehicle, long entryGateNo) { + + return null; + } + + @Override + public ParkingTicketStatus getParkingTicketStatus() { + return null; + } + + @Override + public Double getParkingAmount() { + return null; + } +} diff --git a/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/utility/ParkingUtility.java b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/utility/ParkingUtility.java new file mode 100644 index 0000000..587fe86 --- /dev/null +++ b/LowLevelDesign/ParkingLot/src/com/msdeepsingh/parkinglot/utility/ParkingUtility.java @@ -0,0 +1,10 @@ +package com.msdeepsingh.parkinglot.utility; + +import com.msdeepsingh.parkinglot.model.parking.ParkingSpot; +import com.msdeepsingh.parkinglot.model.parking.ParkingSpotType; + +public class ParkingUtility { + public static ParkingSpot createParkingSpot(long spotNumber, ParkingSpotType parkingSpotType) { + return new ParkingSpot(spotNumber, parkingSpotType); + } +}