-
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
done #1296
base: master
Are you sure you want to change the base?
done #1296
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! 😊 There are a few critical issues that need to be addressed before we can approve the pull request. The remove
method in the Storage
class should update the quantity of the fruit rather than removing it from the map. It's essential to ensure that the resulting quantity is non-negative before updating the map. If the balance is negative, a RuntimeException
should be thrown, as specified in the task checklist. Once these issues are resolved, your code will be in great shape! Keep up the great work! 💪
✨ 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 { | ||
@Override | ||
public void apply(FruitTransaction transaction) { | ||
Storage.remove(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 Storage.remove
method checks if the resulting quantity is non-negative before updating the storage. Throw a RuntimeException
if the balance is negative, as specified in the checklist: "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 remove(String fruit, int quantity) { | ||
fruits.remove(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 remove
method should update the quantity of the fruit instead of removing it from the map. Use fruits.put(fruit, fruits.getOrDefault(fruit, 0) - quantity)
to update the quantity. Additionally, ensure that the resulting quantity is non-negative before updating the map, and throw a RuntimeException
if the balance is negative, as specified in the checklist.
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 mostly on point, but there's a critical issue that needs to be addressed before we can approve the pull request. The remove
method in the Storage
class is currently using Map.remove(Object key, Object value)
, which is not suitable for updating quantities. This could lead to incorrect stock levels. Please ensure that the method updates the quantity correctly and checks for non-negative values, throwing a RuntimeException
if the balance becomes negative. Once you address this, your code will be in great shape! Keep up the great work! 🌟
✨ 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 { | ||
@Override | ||
public void apply(FruitTransaction transaction) { | ||
Storage.remove(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 Storage.remove
method checks if the resulting quantity is non-negative before updating the storage. If the balance becomes negative, throw a RuntimeException
to handle this case. This is important to prevent negative stock levels in the storage.
public static void remove(String fruit, int quantity) { | ||
fruits.remove(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 remove
method should update the quantity of the fruit instead of using Map.remove(Object key, Object value)
. Ensure that the quantity does not become negative. If the resulting quantity is negative, throw a RuntimeException
to handle this case.
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 implementing the solution! 🎉 Your code demonstrates a solid understanding of the task requirements and effectively addresses the main functionality. However, there are a few areas for improvement:
-
Package Structure: Ensure your classes are organized into the recommended package structure, such as placing the
Storage
class in adb
package. -
SOLID Principles: Consider refactoring the
Storage
class to adhere to the Dependency Inversion Principle by avoiding direct static access. -
Encapsulation: Make the
fruits
map in theStorage
class private and provide access through methods to maintain encapsulation. -
Exception Handling: Improve the exception messages in the
PurchaseOperation
class to provide more informative feedback. -
File Management: Ensure that files for reading from and writing to CSV files are included in the
src/main/resources
folder.
These improvements will enhance the maintainability and robustness of your code. Remember, addressing these issues will not only help you in this project but also in future endeavors. Keep up the good work, and continue learning from each experience! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
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.
Review Summary
Great job on implementing the BalanceOperation
, DataConverter
, and other classes! Your code demonstrates a solid understanding of interfaces and the strategy pattern. 🎉
However, there are a few areas that need improvement:
-
Exception Handling: In the
PurchaseOperation
class, the exception handling could be more informative. Consider providing more context in the exception message, such as including the fruit type and the attempted quantity, to make debugging easier. -
Package Structure: The project would benefit from a more organized package structure. Consider separating your classes into packages like
db
,model
,service
,service.impl
, andstrategy
. -
SOLID Principles: Ensure that all services are independent and adhere to SOLID principles. The
main()
method should orchestrate the flow by calling independent services. -
File Placement: Input and output files should ideally be placed in the
src/main/resources
folder to maintain a clean project structure. -
Avoid Hardcoding: Try to avoid hardcoding file paths and other values outside of the
Main
class.
The decision to approve is made to help you move forward with your learning. Please review the comments and address these issues in future iterations to enhance the quality and maintainability of your code. Keep up the good work and continue to learn from these experiences! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
} catch (RuntimeException e) { | ||
throw new RuntimeException("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.
Consider providing more context in the exception message, such as including the fruit type and the attempted quantity, to make debugging easier.
@@ -0,0 +1,8 @@ | |||
package core.basesyntax; |
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.
Let's revise common mistakes file and check project structure
class DataConverterImpl implements DataConverter { | ||
@Override | ||
public List<FruitTransaction> convertToTransaction(List<String> data) { | ||
// Пропускаем первую строку с заголовками |
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.
remove comment
int quantity = Integer.parseInt(parts[2]); | ||
return new FruitTransaction(op, fruit, quantity); | ||
}) | ||
.collect(Collectors.toList()); |
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.
.collect(Collectors.toList()); | |
.toList(); |
return data.stream() | ||
.skip(1) | ||
.map(line -> { | ||
String[] parts = line.split(","); |
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.
create constant for comma
.skip(1) | ||
.map(line -> { | ||
String[] parts = line.split(","); | ||
String opCode = parts[0]; |
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.
create constants for all magic numbers
public static void main(String[] arg) throws IOException { | ||
// 1. Read the data from the input CSV file | ||
FileReader fileReader = new FileReaderImpl(); | ||
List<String> inputReport = fileReader.read("reportToRead.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.
input and output files should be in resources
folder
create constants for files pathes
public String getReport() { | ||
StringBuilder report = new StringBuilder(); | ||
Storage.getFruits().forEach((fruit, quantity) -> report.append(fruit) | ||
.append(",") |
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.
create constant for comma
Storage.getFruits().forEach((fruit, quantity) -> report.append(fruit) | ||
.append(",") | ||
.append(quantity) | ||
.append("\n")); |
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.
Use System.lineSeparator()
instead of "\n"
|
||
import java.util.List; | ||
|
||
class ShopServiceImpl implements ShopService { |
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.
class ShopServiceImpl implements ShopService { | |
public class ShopServiceImpl implements ShopService { |
} | ||
} | ||
|
||
public static Map<String, Integer> getFruits() { |
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.
redundant method
import java.util.Map; | ||
|
||
public class Main { | ||
private static final String REPORT_TO_READ_FILE_PATH = "reportToRead.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.
files should be placed in resources folder
|
||
public String getCode() { | ||
return code; | ||
} |
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.
You can also check if particular code exists in public static Operation getOperation(String code)
String[] parts = line.split(SEPARATOR_SIGN); | ||
String opCode = parts[OPERATOR_PART]; | ||
FruitTransaction.Operation op = switch (opCode) { | ||
case "b" -> FruitTransaction.Operation.BALANCE; |
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.
let's use getOperation(code) method instead of switch case
See comment in FruitTransaction
No description provided.