Implement steamPractice methods#1394
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
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.
- Incorrect odd number check: In
StreamPractice.java, the filtern % 2 == 1in thegetOddNumsAveragemethod doesn't work for negative odd numbers. For instance,-3 % 2evaluates to-1, causing negative odds to be excluded. Please update this ton % 2 != 0to ensure all odd numbers are correctly handled. - Magic String: The hardcoded string
"Ukrainian"inCandidateValidator.javashould be defined as aprivate static finalconstant. 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
| 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) |
There was a problem hiding this comment.
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") |
There was a problem hiding this comment.
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
left a comment
There was a problem hiding this comment.
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! ✨
No description provided.