Stream Practice solution#1392
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Changes are needed for this submission because it violates two core requirements of the task. While you've done a great job with most of the stream logic, please address the following:
- In
StreamPractice.java, thegetOddNumsAveragemethod uses aforloop. The task requires all solutions to use only the Stream API, without any loops [CHECKLIST ITEM #2]. Consider usingIntStream.range()to process elements by their index within a stream. - In
CandidateValidator.java, the values35,10, and"Ukrainian"are hardcoded. These magic values must be declared asprivate static finalconstants as specified in the checklist [CHECKLIST ITEM #6].
Once these issues are resolved, your solution will be in great shape!
✨ 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
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Excellent work on this iteration! I am approving your solution as you've successfully addressed the previous feedback and met all the core requirements. The use of the Stream API is now correct, and constants are properly implemented.
I have a couple of minor suggestions for future improvements:
- In
CandidateValidator.java, the checkcandidate.getClass() == Candidate.classis redundant. Since thetestmethod parameter is of typeCandidate, this check will always be true and can be removed for cleaner code. - In
StreamPractice.java, the.sorted()method invalidateCandidatesshould be on a new line to adhere to the project's style guide [CHECKLIST ITEM #5].
These are just minor points to keep in mind. Great job completing the task!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| return Collections.emptyList(); | ||
| CandidateValidator validator = new CandidateValidator(); | ||
| return candidates.stream() | ||
| .filter(validator).sorted(Comparator.comparing(Candidate::getName)) |
There was a problem hiding this comment.
This violates checklist item #5: 'Call each new method from a new line in the stream'. The .sorted() method should be moved to a new line to improve readability.
| public boolean test(Candidate candidate) { | ||
| int from = Integer.parseInt(candidate.getPeriodsInUkr().split("-")[0]); | ||
| int to = Integer.parseInt(candidate.getPeriodsInUkr().split("-")[1]); | ||
| return candidate.getClass() == Candidate.class |
There was a problem hiding this comment.
This check candidate.getClass() == Candidate.class is unnecessary. Since this is an implementation of Predicate<Candidate>, the test method will only ever be called with an object that is an instance of Candidate. You can safely remove this part of the condition.
No description provided.