-
Notifications
You must be signed in to change notification settings - Fork 1.2k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
SOLID #1256
base: master
Are you sure you want to change the base?
SOLID #1256
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work on this project! 😊 While your code is well-structured and mostly meets the requirements, there are a few critical issues that need to be addressed before we can approve the pull request:
-
Absolute Path Usage: The use of an absolute path in
Main.java
for reading the CSV file is not recommended. Please switch to a relative path to ensure the project can be run by anyone without modifications. -
Package Structure: The current package structure does not adhere to the recommended organization. Consider organizing your code into packages like
db
,model
,service
,service.impl
, andstrategy
for better maintainability and clarity. -
Handling Purchase Operation: The
PurchaseOperation
class currently does not check if the resulting balance is positive before subtracting the quantity. This is crucial to prevent invalid storage states. Please ensure that aRuntimeException
is thrown if the balance becomes negative. -
Input and Output File Location: Ensure that input and output files are placed in the
src/main/resources
folder as per the checklist.
By addressing these issues, your code will be more robust and aligned with best practices. Keep up the great work, and I'm confident you'll nail it with these adjustments! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
🔄 Fix the issues, commit the changes, and then re-request my review using the Re-request review
button in the Reviewers tab.
|
||
public class PurchaseOperation implements OperationHandler { | ||
public void handle(FruitTransaction transaction) { | ||
Storage.subtract(transaction.getFruit(), transaction.getQuantity()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that the resulting balance in the storage is not negative after a purchase. If it is, throw a RuntimeException
as per the checklist requirement: 'Handling Purchase operation. Check result balance before saving it in the Storage - it should be positive. Throw RuntimeException
in case the balance is negative.'
public static void subtract(String fruit, int quantity) { | ||
fruits.put(fruit, fruits.getOrDefault(fruit, 0) - quantity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ensure that the resulting quantity after subtraction is not negative. If it is, throw a RuntimeException
to prevent invalid storage states. This aligns with the checklist requirement: 'Handling Purchase operation. Check result balance before saving it in the Storage - it should be positive. Throw RuntimeException
in case the balance is negative.'
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Great job on your progress! 🎉 While there are still a few critical issues to address, such as ensuring file paths are relative for portability and adding necessary checks to prevent invalid states or exceptions, your implementation is on the right track.
Here are some key points to focus on:
-
File Paths: Ensure both input and output file paths are relative to make your project more portable. Consider using paths like
"src/main/resources/input.csv"
and"src/main/resources/finalReport.csv"
. -
Data Validation: Add validation in
DataConverterImpl.java
to handle potential parsing errors, ensuring that the input data is well-formed and any exceptions are managed gracefully. -
Operation Handling: In
OperationStrategyImpl.java
, add checks to handle cases where an operation might not have a corresponding handler to preventNullPointerException
. -
Storage Integrity: Update the
subtract
method inStorage.java
to check for negative quantities and throw an exception if necessary, maintaining data integrity.
These improvements will enhance the robustness and reliability of your code. Keep up the good work, and make sure to address these issues in future iterations to avoid similar problems. Your dedication to learning and improving is commendable! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
String finalReport = reportGenerator.getReport(); | ||
|
||
MyFileWriter fileWriter = new FileWriterImpl(); | ||
fileWriter.write(finalReport, "src/main/resources/finalReport.csv"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output file path should be relative to ensure the project can be run by anyone without modifications. Consider using a path like "src/main/resources/finalReport.csv"
.
} | ||
|
||
public static void subtract(String fruit, int quantity) { | ||
fruits.put(fruit, fruits.getOrDefault(fruit, 0) - quantity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The subtract
method should check if the resulting quantity is negative before updating the storage. Consider throwing a RuntimeException
if the subtraction would result in a negative quantity, to prevent invalid storage states.
for (int i = 1; i < rawData.size(); i++) { | ||
String[] parts = rawData.get(i).split(","); | ||
FruitTransaction.Operation operation = FruitTransaction.Operation.fromCode(parts[0]); | ||
String fruit = parts[1]; | ||
int quantity = Integer.parseInt(parts[2]); | ||
fruitTransactions.add(new FruitTransaction(operation, fruit, quantity)); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation assumes that the input data is always well-formed. Consider adding validation to handle potential parsing errors, such as checking if parts
has the expected length and catching NumberFormatException
when parsing the quantity.
} | ||
|
||
public OperationHandler getOperationHandler(FruitTransaction.Operation operation) { | ||
return operationHandlers.get(operation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a check to handle cases where the operationHandlers
map does not contain a handler for the given operation. You might want to throw an exception or return a default handler in such cases.
OperationHandler handler = operationStrategy | ||
.getOperationHandler(transaction.getOperation()); | ||
handler.handle(transaction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a check to handle cases where getOperationHandler
might return null
if a handler is not found for a given operation. This will prevent potential NullPointerException
and improve robustness.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thank you for your hard work on this project! 🎉 Your code is well-structured and mostly meets the task requirements. However, there are a few critical issues that need attention to ensure the functionality and robustness of your code:
-
File Path Management: Ensure both the input (
toRead.csv
) and output (finalReport.csv
) files are placed in thesrc/main/resources
folder. This will help avoid file path issues and make your code more portable. -
Error Handling in Data Parsing: The
DataConverterImpl.java
assumes that the raw data is always correctly formatted. Consider adding error handling to manage cases where the data might be malformed, such as catchingArrayIndexOutOfBoundsException
orNumberFormatException
. -
Operation Handler Strategy: In
OperationStrategyImpl.java
, add a check to handle cases where an operation does not have a corresponding handler in the map. This will prevent potentialNullPointerException
and improve the robustness of your code. -
Storage Integrity: In
Storage.java
, ensure thesubtract
method checks if the resulting quantity is negative before updating the map. Throw aRuntimeException
if the quantity becomes negative to maintain data integrity.
These improvements are crucial for the functionality of your application. Please address these issues in future iterations to enhance your code quality. Keep up the great work and continue learning from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
String finalReport = reportGenerator.getReport(); | ||
|
||
MyFileWriter fileWriter = new FileWriterImpl(); | ||
fileWriter.write(finalReport, "src/main/resources/finalReport.csv"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The output file path should be relative and placed in the src/main/resources
folder as per the checklist. Consider changing the path to src/main/resources/finalReport.csv
.
public static void subtract(String fruit, int quantity) { | ||
fruits.put(fruit, fruits.getOrDefault(fruit, 0) - quantity); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The subtract
method should check if the resulting quantity is negative before updating the map. If the quantity becomes negative, consider throwing a RuntimeException
to prevent invalid states in the storage.
String[] parts = rawData.get(i).split(","); | ||
FruitTransaction.Operation operation = FruitTransaction.Operation.fromCode(parts[0]); | ||
String fruit = parts[1]; | ||
int quantity = Integer.parseInt(parts[2]); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The current implementation assumes that the raw data is always correctly formatted. Consider adding error handling to manage cases where the data might be malformed, such as catching ArrayIndexOutOfBoundsException
or NumberFormatException
.
public OperationHandler getOperationHandler(FruitTransaction.Operation operation) { | ||
return operationHandlers.get(operation); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a check to handle cases where an operation does not have a corresponding handler in the map. You could throw an exception or return a default handler to prevent potential NullPointerException
.
OperationHandler handler = operationStrategy | ||
.getOperationHandler(transaction.getOperation()); | ||
handler.handle(transaction); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Consider adding a check to handle cases where getOperationHandler
returns null
. This could happen if a transaction's operation does not have a corresponding handler, leading to a NullPointerException
when calling handle
.
No description provided.