Skip to content

Implement steamPractice methods#1394

Open
edzikowicz wants to merge 2 commits into
mate-academy:mainfrom
edzikowicz:main
Open

Implement steamPractice methods#1394
edzikowicz wants to merge 2 commits into
mate-academy:mainfrom
edzikowicz:main

Conversation

@edzikowicz

Copy link
Copy Markdown

No description provided.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

Great job on the implementation! Your use of the Stream API is clean and well-structured. However, a couple of changes are needed before this can be approved.

  1. Incorrect odd number check: In StreamPractice.java, the filter n % 2 == 1 in the getOddNumsAverage method doesn't work for negative odd numbers. For instance, -3 % 2 evaluates to -1, causing negative odds to be excluded. Please update this to n % 2 != 0 to ensure all odd numbers are correctly handled.
  2. Magic String: The hardcoded string "Ukrainian" in CandidateValidator.java should be defined as a private static final constant. This is a requirement from the checklist [CHECKLIST ITEM #6] and improves code maintainability.

Once these two issues are addressed, your solution will be ready to go. Keep up the excellent work!


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

Important

Fix the issues, commit the changes, and then re-request my review using the Re-request review button2 in the Reviewers tab.

Tip

If you have any comments about this review, please leave a message in the Add a comment section below and mention me with the @mateacademy-ai-mentor tag3.
I will read your message during my next review of your pull request. Please do not reply directly to my comments, as that feature is not supported yet.

Caution

Do not close the pull request until the review is complete. Closing it early can lead to unexpected behavior and disrupt the review process.

Footnotes

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

return 0D;
return IntStream.range(0, numbers.size())
.map(i -> i % 2 != 0 ? numbers.get(i) - 1 : numbers.get(i))
.filter(n -> n % 2 == 1)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

The current filter n % 2 == 1 correctly identifies positive odd numbers, but it will exclude negative odd numbers. In Java, the result of the modulo operator for a negative number is negative (e.g., -3 % 2 is -1). To ensure all odd numbers are included, consider using a condition that works for both positive and negative values, such as n % 2 != 0.

int periodInUkrTo = Integer.parseInt(years[1]);
return candidate.getAge() >= MIN_CANDIDATE_AGE
&& candidate.isAllowedToVote()
&& candidate.getNationality().equals("Ukrainian")

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

This hardcoded string "Ukrainian" is considered a 'magic string'. According to checklist item #6, it's better practice to define it as a private static final constant at the top of the class, similar to how you've handled MIN_CANDIDATE_AGE and MIN_PERIOD_IN_UKR. This improves readability and makes the code easier to maintain.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Review Summary

Excellent work on this submission! I am happy to confirm that your solution is complete. You've done a great job addressing all the feedback from the previous review. The logic for checking odd numbers is now correct for all integers, and you've properly replaced the hardcoded nationality string with a constant in CandidateValidator. The entire solution is clean, readable, and correctly implements all requirements using the Stream API. Well done!


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

Footnotes

  1. Rate AI review example

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