-
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
first_attempt #1283
base: master
Are you sure you want to change the base?
first_attempt #1283
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 meets many of the task requirements, there are a few critical issues that need to be addressed before we can approve the pull request. Specifically, the PurchaseOperation
class should check for negative balances and throw a RuntimeException
if necessary. Additionally, exception handling in FileWriterImpl
should be improved by including the exception object for better error tracking. Please also ensure that file paths are relative and that the package structure aligns with the 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.
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.
Sorry, the pull request review was unsuccessful for the following reasons:
Warning
Something went wrong while processing the review.
[CODE: 3]
If the issue is within your control, please address it.
The next review attempt will automatically launch in 1 hour.
If you believe this is an error or need assistance, please contact the support team.
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 addressing the previous review comments and aligning your code with the task requirements! 🎉 Your implementation is well-structured, and the package organization is on point. Here are a few key points from the review:
-
PurchaseOperation Class: You've successfully implemented a check for negative balances, throwing a
RuntimeException
when necessary. This is crucial for maintaining data integrity during purchase operations. -
FileWriterImpl Class: The improvement in exception handling by including the exception object in the
RuntimeException
is a significant enhancement for error tracking. -
Relative File Paths: Using relative paths ensures that your project is accessible and runnable by anyone, which is a great practice.
-
Package Structure: Your classes are well-organized into appropriate packages, which enhances the readability and maintainability of your code.
While the code meets the task requirements, remember to address any critical issues in future projects to avoid similar problems. For instance, ensure that exception handling in all classes, such as FileReaderImpl
, includes the exception object for detailed error information. This will help you provide more context about errors and improve debugging.
Keep up the great work, and continue learning from these experiences to enhance your coding skills! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
} catch (IOException e) { | ||
throw new RuntimeException("Error reading file: " + fileName); |
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 exception handling here should include the exception object e
in the RuntimeException
to provide more detailed error information. Modify the line to: throw new RuntimeException("Error reading file: " + fileName, e);
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.
Good job! Let’s improve your solution ;)
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class FileReaderImpl implements FileReaderMy { |
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.
public class FileReaderImpl implements FileReaderMy { | |
public class CustomFileReaderImpl implements CustomFileReader { |
import java.io.BufferedWriter; | ||
import java.io.IOException; | ||
|
||
public class FileWriterImpl implements FileWriterMy { |
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 same
try (BufferedWriter bufferedWriter = new BufferedWriter(new java.io.FileWriter(fileName))) { | ||
bufferedWriter.write(info); | ||
} catch (IOException e) { | ||
throw new RuntimeException("Impossible to write in this file " + fileName, e); |
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.
throw new RuntimeException("Impossible to write in this file " + fileName, e); | |
throw new RuntimeException("Can’t write file with path: " + fileName, e); |
Make the message more formal
|
||
@Override | ||
public String getReport(Map<String, Integer> storage) { | ||
StringJoiner report = new StringJoiner("\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.
better use System.lineseparator()
report.add("fruit,quantity"); | ||
|
||
for (Map.Entry<String, Integer> entry : storage.entrySet()) { | ||
report.add(entry.getKey() + "," + entry.getValue()); |
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.
make header and separator constant fields
inputReport.stream() | ||
.skip(1L) | ||
.map(line -> line.split(",")) | ||
.filter(parts -> parts.length == 3) |
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 should throw an exception for invalid data
|
||
public class BalanceOperation implements OperationHandler { | ||
@Override | ||
public void handle(Map<String, Integer> storage, FruitTransaction 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.
Storage imitates real databases. So create a Storage class with a public static map
public void handle(Map<String, Integer> storage, FruitTransaction transaction) { | ||
storage.put(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.
public void handle(Map<String, Integer> storage, FruitTransaction transaction) { | |
storage.put(transaction.getFruit(), transaction.getQuantity()); | |
public void handle(FruitTransaction transaction) { | |
Storage.storage.put(transaction.getFruit(), transaction.getQuantity()); |
|
||
@Override | ||
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.
better check that strategy return handler
} | ||
|
||
@Override | ||
public Map<String, Integer> process(List<FruitTransaction> transactions) { |
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.
public Map<String, Integer> process(List<FruitTransaction> transactions) { | |
public void process(List<FruitTransaction> transactions) { |
use Storage
No description provided.