-
Notifications
You must be signed in to change notification settings - Fork 1.4k
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
Implemented method getStatistic #1619
base: master
Are you sure you want to change the base?
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 implementation of the WorkWithFile
class is mostly correct, there are a few critical issues that need to be addressed before we can approve the pull request. These issues impact the robustness and correctness of the code:
-
Exception Handling: The code currently ignores exceptions by returning from the method without any message or re-throwing. This can make debugging difficult. It's important to log exceptions or rethrow them with a meaningful message to provide context.
-
Operation Type Assumptions: The code assumes that any operation other than 'supply' is 'buy'. This could lead to incorrect calculations if unexpected operation types are encountered. Adding a check for 'buy' and handling unexpected operations appropriately is crucial.
-
File Existence Check: While checking for file existence is good, returning immediately without notification or exception handling might not be the best approach. Consider logging a message or throwing an exception to inform the caller that the file does not exist.
Please address these issues to ensure the code meets the task requirements and constraints. Once resolved, we can proceed with the approval. Keep up the great work, and don't hesitate to reach out if you need any help! 🚀
✨ 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.
if (!file.exists()) { | ||
return; | ||
} |
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 check for file existence is good, but returning immediately without any notification or exception handling might not be the best approach. Consider logging a message or throwing an exception to inform the caller that the file does not exist.
} else { | ||
buyTotal += amount; | ||
} |
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 code assumes that any operation other than 'supply' is 'buy'. This might lead to incorrect calculations if there are unexpected operation types in the file. Consider adding a check for 'buy' and handling unexpected operations appropriately, perhaps by logging a warning or throwing an exception.
} | ||
} | ||
} catch (IOException e) { | ||
return; |
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.
Returning immediately on an IOException without any notification or logging might make it difficult to debug issues. Consider logging the exception or rethrowing it to provide more context to the caller.
writer.newLine(); | ||
writer.write("result," + result); | ||
} catch (IOException e) { | ||
return; |
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.
Similar to the previous catch block, consider logging the IOException or rethrowing it to provide more context and aid in debugging.
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 making improvements to the WorkWithFile
class! 🎉 While there are still some critical issues that need attention, your progress is commendable. Here are the key areas to focus on:
-
Exception Handling: It's crucial to handle exceptions more robustly. Instead of just printing error messages to the console, consider re-throwing exceptions with meaningful messages to provide better context for debugging.
-
Operation Type Assumptions: While the code correctly handles 'supply' and 'buy' operations, it doesn't account for unexpected operation types. Implementing a mechanism to log warnings or throw exceptions for unknown operations would enhance the robustness of your code.
-
File Existence Check: The current implementation only prints a message when a file doesn't exist. To align with task requirements, consider throwing an exception or logging a detailed message to inform the caller about the missing file.
-
Use of StringBuilder: For better performance, especially in loops or multiple concatenations, use
StringBuilder
instead of string concatenation within theBufferedWriter
block. -
Method Length and Responsibility: The
getStatistic
method is handling multiple responsibilities. Breaking it down into smaller, focused methods will improve readability and maintainability.
These improvements will not only help you meet the task requirements but also enhance your coding skills. Keep up the good work and continue learning from these experiences. Remember, addressing these issues in future projects will help you avoid similar problems. Happy coding! 🚀
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
System.out.println("the file does not exist."); | ||
return; |
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.
Currently, the code only prints a message when the file does not exist and then returns. Consider throwing an exception or logging a more detailed message to inform the caller about the missing file, as per the task requirements.
} | ||
} catch (IOException e) { | ||
System.out.println("Error while reading file: " + e.getMessage()); | ||
return; |
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.
Returning from the method after catching an IOException without further action might not be the best approach. Consider re-throwing the exception or logging it with more context to aid in debugging.
writer.write("result," + result); | ||
} catch (IOException e) { | ||
System.out.println("Error while writing file: " + e.getMessage()); | ||
return; |
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.
Similar to the previous catch block, returning after catching an IOException without further action is not ideal. Consider re-throwing the exception or logging it with more context.
No description provided.