This PR refactors the parkingVehicle method in the ParkingRobot class to improve code readability and reduce complexity. The changes include extracting the logic for finding the correct parking lot into a separate method, updating method calls to use the new method, removing unnecessary checks, and improving the usage of class fields.
Summary of Changes
Extracted the logic for finding the correct parking lot into a separate method called findCorrectLot.
Updated the parkingVehicle method to use the findCorrectLot method instead of inline logic.
Removed the unnecessary check for vehicle.getCarPlateNumber() == null.
Updated the hasSameVehicle method to use the parkingLotList field from the ParkingBoy class.
Updated the findCorrectLot method to use the parkingLotList field from the ParkingBoy class and sort the parking lots based on the empty ratio in ascending order.
Updated the findCorrectLot method to return the first parking lot with available space instead of the one with the highest empty ratio.
Fixes #1.
🎉 Latest improvements to Sweep:
Sweep can now passively improve your repository! Check out Rules to learn more.
💡 To get Sweep to edit this pull request, you can:
Comment below, and Sweep can edit the entire PR
Comment on a file, Sweep will only modify the commented file
Edit the original issue to get Sweep to recreate the PR from scratch
Description
This PR refactors the
parkingVehicle
method in theParkingRobot
class to improve code readability and reduce complexity. The changes include extracting the logic for finding the correct parking lot into a separate method, updating method calls to use the new method, removing unnecessary checks, and improving the usage of class fields.Summary of Changes
findCorrectLot
.parkingVehicle
method to use thefindCorrectLot
method instead of inline logic.vehicle.getCarPlateNumber() == null
.hasSameVehicle
method to use theparkingLotList
field from theParkingBoy
class.findCorrectLot
method to use theparkingLotList
field from theParkingBoy
class and sort the parking lots based on the empty ratio in ascending order.findCorrectLot
method to return the first parking lot with available space instead of the one with the highest empty ratio.Fixes #1.
🎉 Latest improvements to Sweep:
💡 To get Sweep to edit this pull request, you can: