-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Task solution #1322
base: master
Are you sure you want to change the base?
Task solution #1322
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.
Great job on your Pull Request! There are some suggestions to improve the code, like using regular expressions or other methods for parsing data, simplifying date range checks, avoiding magic numbers, and refactoring repeated logic into separate methods. Also, remember to use constants for values that don't change. Keep up the good work, and consider these tips for your next update! 👍🎉
✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨
public class SalaryInfo { | ||
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d.MM.yyyy"); |
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.
Since the formatter is a constant and will not change, it should be declared as a static final field and follow the naming conventions for constants (all uppercase letters with underscores). Consider renaming it to 'DATE_FORMATTER'.
public class SalaryInfo { | ||
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d.MM.yyyy"); | ||
private final int startPositionForSubstringDate = 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.
Consider encapsulating the logic for parsing the date from a string into a separate method. This would avoid the need for these constants and make the code more readable.
public class SalaryInfo { | ||
private final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d.MM.yyyy"); | ||
private final int startPositionForSubstringDate = 0; | ||
private final int endPositionForSubstringDate = 10; |
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.
Magic numbers should be avoided. The positions used for substrings should be constants with informative names to explain their purpose.
LocalDate rowDate = LocalDate.parse(simpleData.substring( | ||
startPositionForSubstringDate, endPositionForSubstringDate), | ||
formatter); | ||
if ((rowDate.isAfter(localDateFrom) || rowDate.isEqual(localDateFrom)) |
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 logic for checking if the date is within the range can be simplified and made more readable by using !rowDate.isBefore(localDateFrom) && !rowDate.isAfter(localDateTo)
, which is equivalent and avoids the need for multiple isEqual
calls.
if ((rowDate.isAfter(localDateFrom) || rowDate.isEqual(localDateFrom)) | ||
&& rowDate.isBefore(localDateTo) || rowDate.isEqual(localDateTo)) { | ||
|
||
String[] dayIncomeInfo = simpleData.substring( |
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.
Extracting the income data substring can be error-prone and hard to maintain. Consider using a different approach to parse the data, such as using a regular expression or splitting the string into parts and then extracting the relevant information.
… forgot about this)) and simplified if statement that checked the data)
public class SalaryInfo { | ||
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d.MM.yyyy"); |
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.
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d.MM.yyyy"); | |
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("dd.MM.yyyy"); |
public class SalaryInfo { | ||
private static final DateTimeFormatter formatter = DateTimeFormatter.ofPattern("d.MM.yyyy"); | ||
private static final int startPositionForSubstringDate = 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.
read about naming convention for constants and refactor them
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.
Agree, my bad(
I've read it before, just forgot. Tomorrow morning I will send fixed version.
…s, change pattern in formatter)
No description provided.