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

Hw 14 jv stream practice #1197

Open
wants to merge 14 commits into
base: main
Choose a base branch
from

Conversation

skrypkasv
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 implementing the core functionality and meeting most of the task requirements! 🎉 While there are a few areas for improvement, such as enhancing exception handling and clarifying certain logic, these are minor and do not significantly impact the overall functionality of your code. Keep up the good work, and consider the feedback to make your code even more robust and maintainable in the future. 😊

✨ Please rate this review in the Platform's notification center. I will be grateful for your feedback! ✨


@Override
public boolean test(Candidate candidate) {
String[] years = candidate.getPeriodsInUkr().split("-");

Choose a reason for hiding this comment

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

Ensure that the getPeriodsInUkr() method in the Candidate class returns a valid string in the format 'YYYY-YYYY'. If the format is incorrect, ArrayIndexOutOfBoundsException or NumberFormatException might occur.

Comment on lines +14 to +15
int fromYear = Integer.parseInt(years[0]);
int toYear = Integer.parseInt(years[1]);

Choose a reason for hiding this comment

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

Consider adding error handling for NumberFormatException in case the years cannot be parsed into integers. This will make the code more robust against invalid input.

Comment on lines +21 to +22
.orElseThrow(() -> new RuntimeException("Can't get min value from list: "
+ numbers));

Choose a reason for hiding this comment

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

The use of RuntimeException in orElseThrow is acceptable, but consider using a more specific exception type or a custom exception to provide clearer context about the error.

Comment on lines +26 to +27
return IntStream.range(0, numbers.size())
.map(i -> (i % 2 != 0) ? numbers.get(i) - 1 : numbers.get(i))

Choose a reason for hiding this comment

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

The logic for adjusting numbers at odd indices by subtracting 1 is not immediately clear. Ensure this logic is intentional and documented, as it may confuse future maintainers.

.map(i -> (i % 2 != 0) ? numbers.get(i) - 1 : numbers.get(i))
.filter(n -> n % 2 != 0)
.average()
.orElseThrow(NoSuchElementException::new);

Choose a reason for hiding this comment

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

Throwing NoSuchElementException is appropriate here, but consider providing a custom message to clarify the context of the exception.

Copy link
Contributor

@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! But please pay attention to my comments ;)


@Override
public boolean test(Candidate candidate) {
String[] years = candidate.getPeriodsInUkr().split("-");
Copy link
Contributor

Choose a reason for hiding this comment

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

better make separator constant field

Comment on lines 19 to 20
.sorted()
.findFirst()
Copy link
Contributor

Choose a reason for hiding this comment

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

you can replace it using min()

.filter(p -> p.getSex() == Person.Sex.MAN
&& p.getAge() >= fromAge
&& p.getAge() <= toAge)
.collect(Collectors.toList());
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
.collect(Collectors.toList());
.toList();

Let’s fix it everywhere

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.

3 participants