Skip to content
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

Open
wants to merge 4 commits into
base: master
Choose a base branch
from
Open

Conversation

justVovan4ik
Copy link

No description provided.

Copy link

@mateacademy-ai-mentor mateacademy-ai-mentor left a 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");

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;

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;

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))

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(

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");

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
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;

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

Copy link
Author

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants