solution for jv-stream-github-practise#1404
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution has critical functionality issues that must be addressed. The most serious problem is an operator precedence bug in getWorkablePeople(): the boolean expression (MAN && age <= maleToAge && age >= fromAge) || (WOMAN && age <= femaleToAge) && age >= fromAge doesn't group correctly, causing the men's lower age bound (fromAge) to never be enforced — this breaks Task 4's core logic. Additionally, findMinEvenNumber() throws an exception message without the numbers parameter (CHECKLIST #11), and CandidateValidator uses magic values (35, "Ukrainian", 10) instead of named constants (CHECKLIST #9). Please fix the operator precedence by adding parentheses around each gender condition, include the numbers parameter in the exception message, and replace all hardcoded values with constants.
✨ 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
| public int findMinEvenNumber(List<String> numbers) { | ||
| return 0; | ||
| if (numbers.isEmpty()) { | ||
| throw new RuntimeException("Can't get min value from list"); |
There was a problem hiding this comment.
Checklist item #11 violation: The exception message should be "Can't get min value from list: " + numbers, but currently it only throws "Can't get min value from list" without appending the input parameter.
| public boolean test(Candidate candidate) { | ||
| String[] period = candidate.getPeriodsInUkr().split("-"); | ||
| int periodInt = Integer.parseInt(period[1]) - Integer.parseInt(period[0]); | ||
| return candidate.getAge() >= 35 |
There was a problem hiding this comment.
Checklist item #9 violation: Use constants instead of magic numbers/strings. Replace the hardcoded age value 35 with a named constant like MIN_AGE.
| String[] period = candidate.getPeriodsInUkr().split("-"); | ||
| int periodInt = Integer.parseInt(period[1]) - Integer.parseInt(period[0]); | ||
| return candidate.getAge() >= 35 | ||
| && candidate.getNationality().equals("Ukrainian") |
There was a problem hiding this comment.
Checklist item #9 violation: Use constants instead of magic numbers/strings. Replace the hardcoded string "Ukrainian" with a named constant.
| int periodInt = Integer.parseInt(period[1]) - Integer.parseInt(period[0]); | ||
| return candidate.getAge() >= 35 | ||
| && candidate.getNationality().equals("Ukrainian") | ||
| && periodInt >= 10 && candidate.isAllowedToVote(); |
There was a problem hiding this comment.
Checklist item #9 violation: Use constants instead of magic numbers/strings. Replace the hardcoded value 10 with a named constant representing minimum years in Ukraine.
| return candidate.getAge() >= 35 | ||
| && candidate.getNationality().equals("Ukrainian") | ||
| && periodInt >= 10 && candidate.isAllowedToVote(); | ||
| } |
There was a problem hiding this comment.
Checklist item #11 violation: The exception message must include the input parameter. Change to: throw new RuntimeException("Can't get min value from list: " + numbers);
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Two critical issues remain that block approval. First, the operator precedence bug in getWorkablePeople() (lines 86-92) is still not fixed - the men's lower age bound (fromAge) is not being enforced due to incorrect parentheses grouping. The expression (MAN && age <= maleToAge && age >= fromAge) || (WOMAN && age <= femaleToAge) && age >= fromAge is parsed as (MAN && ... && ...) || ((WOMAN && ...) && age >= fromAge), meaning fromAge only applies to women. This causes men to pass even when they're above maleToAge because the second part of the OR is always false for men, short-circuiting to true. Wrap each complete gender condition in parentheses to fix this [CHECKLIST #4]. Second, the exception message in findMinEvenNumber() is missing the required colon and space - it should be "Can't get min value from list: " + numbers (note the : after "list") [CHECKLIST #11]. Please fix both issues and resubmit.
✨ 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
| public boolean test(Candidate candidate) { | ||
| String[] period = candidate.getPeriodsInUkr().split("-"); | ||
| int periodInt = Integer.parseInt(period[1]) - Integer.parseInt(period[0]); | ||
| return candidate.getAge() >= MIN_AGE |
There was a problem hiding this comment.
The exception message format does not match checklist #11 requirement. It should include a colon and space before the numbers parameter. Change to: "Can't get min value from list: " + numbers
| public int findMinEvenNumber(List<String> numbers) { | ||
| return 0; | ||
| if (numbers.isEmpty()) { | ||
| throw new RuntimeException("Can't get min value from list" + numbers); |
There was a problem hiding this comment.
This violates checklist item #11: the exception message must include the numbers parameter after a colon. Should be "Can't get min value from list: " + numbers
| return peopleList.stream() | ||
| .filter(s -> (s.getSex().equals(Person.Sex.MAN) | ||
| && s.getAge() <= maleToAge | ||
| && s.getAge() >= fromAge) | ||
| || s.getSex().equals(Person.Sex.WOMAN) | ||
| && s.getAge() <= femaleToAge | ||
| && s.getAge() >= fromAge) |
There was a problem hiding this comment.
Operator precedence bug - parentheses only wrap the men's condition. Due to && having higher precedence than ||, the expression evaluates as (MAN && maleToAge && fromAge) || (WOMAN && femaleToAge) && fromAge. The men's fromAge check is correctly applied, but women's is grouped incorrectly. More critically: a 65-year-old man (age > maleToAge) will still pass because the second part (WOMAN && femaleToAge) is always false for men, causing the entire OR to short-circuit to true. Add parentheses around EACH gender condition: (s.getSex().equals(Person.Sex.MAN) && s.getAge() >= fromAge && s.getAge() <= maleToAge) || (s.getSex().equals(Person.Sex.WOMAN) && s.getAge() >= fromAge && s.getAge() <= femaleToAge)
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved with an educational override to help you progress while learning. You did an excellent job fixing the operator precedence bug in getWorkablePeople() with proper parentheses grouping, and most tasks are implemented correctly. However, there's one remaining issue in findMinEvenNumber() at line 22: the exception message is missing a colon and space after "list". The current message "Can't get min value from list" + numbers should be "Can't get min value from list: " + numbers [CHECKLIST ITEM #11]. This is a quick fix—just add : after "list" and before the space. Keep up the good work on your stream operations and filtering logic!
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
Footnotes
| public boolean test(Candidate candidate) { | ||
| String[] period = candidate.getPeriodsInUkr().split("-"); | ||
| int periodInt = Integer.parseInt(period[1]) - Integer.parseInt(period[0]); | ||
| return candidate.getAge() >= MIN_AGE |
There was a problem hiding this comment.
This violates checklist item #11 - the exception message is missing a colon and space after "list". It should be "Can't get min value from list: " + numbers (note the : after "list").
| if (numbers.isEmpty()) { | ||
| throw new RuntimeException("Can't get min value from list" + numbers); |
There was a problem hiding this comment.
The exception message format is incorrect - it's missing a colon and space. Per the checklist requirement, it should be: "Can't get min value from list: " + numbers
No description provided.