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

Solution #1374

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

Solution #1374

wants to merge 4 commits into from

Conversation

MaybeTI
Copy link

@MaybeTI MaybeTI commented Nov 25, 2024

No description provided.

Copy link

@liliia-ponomarenko liliia-ponomarenko left a comment

Choose a reason for hiding this comment

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

Let's check the common mistakes list and fix your solution by list ;)

Comment on lines 7 to 9
private static final DateTimeFormatter DATE_FORMATTER = (
DateTimeFormatter.ofPattern("dd.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 DATE_FORMATTER = (
DateTimeFormatter.ofPattern("dd.MM.yyyy")
);
private static final DateTimeFormatter DATE_FORMATTER =
DateTimeFormatter.ofPattern("dd.MM.yyyy");

redundant brackets

Copy link
Author

Choose a reason for hiding this comment

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

Is this a best practice in Java?

Choose a reason for hiding this comment

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

yes, don't complicate the code unnecessarily

return null;
StringBuilder result = new StringBuilder(
"Report for period "
).append(dateFrom).append(" - ").append(dateTo).append("\n");

Choose a reason for hiding this comment

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

Create constant variables for all literals like HEADER, SEPARATOR, etc.
Use System.lineseparator instead of "\n"

Comment on lines 28 to 31
if (
workerName.equals(name) && (date.isEqual(fromDate)
|| date.isEqual(toDate)
|| (date.isAfter(fromDate) && date.isBefore(toDate)))

Choose a reason for hiding this comment

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

better move this conditional to the private method

result.append(name).append(" - ").append(salary).append("\n");
}

return result.deleteCharAt(result.length() - 1).toString();

Choose a reason for hiding this comment

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

think how you can avoid .deleteCharAt

Copy link

@liliia-ponomarenko liliia-ponomarenko left a comment

Choose a reason for hiding this comment

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

Good job! A few minor comments ;)

}
result[i + 1] = name + SEPARATOR + salary;
}
return String.join("\n", result);

Choose a reason for hiding this comment

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

Suggested change
return String.join("\n", result);
return String.join(System.lineseparator(), result);

Comment on lines +7 to +8
private static String HEADER = "Report for period ";
private static String SEPARATOR = " - ";

Choose a reason for hiding this comment

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

Suggested change
private static String HEADER = "Report for period ";
private static String SEPARATOR = " - ";
private static final String HEADER = "Report for period ";
private static final String SEPARATOR = " - ";

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.

2 participants