Finish README task#1407
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
The solution has multiple critical issues that will cause runtime failures or incorrect output: 1. NullPointerException: Both StreamPractice.java and CandidateValidator.java use flatMapToInt(null) which will crash. You need to split each string by comma and parse: flatMapToInt(s -> Arrays.stream(s.split(",")).mapToInt(Integer::parseInt)) 2. Wrong filter condition: findMinEvenNumber filters odd numbers (n % 2 != 0) instead of even. Change to n % 2 == 0 3. Missing required operation: getOddNumsAverage never subtracts 1 from elements at odd positions as the task requires. Change to map(i -> numbers.get(i) - 1) 4. Incomplete validation: Women's age check in getWorkablePeople only validates p.getAge() <= femaleToAge but is missing the lower bound >= fromAge 5. Enum comparison violations [CHECKLIST #5]: All methods use == instead of .equals() for Enum values. Use p.getSex().equals(Person.Sex.MAN) 6. Magic numbers [CHECKLIST #8]: CandidateValidator uses hardcoded values (35, 10, "Ukrainian") instead of constants. Define MIN_AGE = 35, UKRAINIAN_NATIONALITY = "Ukrainian", and MIN_YEARS_IN_UKRAINE = 10 7. Missing exception handling [CHECKLIST #12]: Add .orElseThrow(() -> new RuntimeException("Can't get min value from list: " + numbers)) when no even numbers exist Focus on fixing the functional bugs first—the checklist violations will be verified separately.
✨ 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
| import model.Candidate; | ||
| import model.Cat; | ||
| import model.Person; | ||
|
|
There was a problem hiding this comment.
This line uses magic number 35 instead of a constant. Per checklist item #8, use constants for all magic numbers and strings in CandidateValidator class.
| */ | ||
| public int findMinEvenNumber(List<String> numbers) { | ||
| return 0; | ||
| return numbers.stream() |
There was a problem hiding this comment.
This line uses magic number 10 instead of a constant. Per checklist item #8, use constants for all magic numbers and strings in CandidateValidator class.
| public int findMinEvenNumber(List<String> numbers) { | ||
| return 0; | ||
| return numbers.stream() | ||
| .flatMapToInt(null) |
There was a problem hiding this comment.
flatMapToInt(null) will cause NullPointerException. Should parse each string by splitting on comma and converting to integers. Use flatMapToInt(s -> Arrays.stream(s.split(",")).mapToInt(Integer::parseInt)) instead.
| return 0; | ||
| return numbers.stream() | ||
| .flatMapToInt(null) | ||
| .filter(n -> n % 2 != 0) |
There was a problem hiding this comment.
Filter keeps ODD numbers (n % 2 != 0), but the task requires EVEN numbers. Change to n % 2 == 0.
| .flatMapToInt(null) | ||
| .filter(n -> n % 2 != 0) | ||
| .min() | ||
| .getAsInt(); |
There was a problem hiding this comment.
No RuntimeException is thrown when no even numbers are found. Per checklist item #12, should throw RuntimeException with message "Can't get min value from list: " + numbers when getAsInt() fails.
| String[] years = c.getPeriodsInUkr().split("-"); | ||
| if (Integer.parseInt(years[1]) - Integer.parseInt(years[0]) < 10) { | ||
| return false; | ||
| } |
There was a problem hiding this comment.
Filter checks for odd numbers (n % 2 != 0) but task requires even numbers. Change to: n % 2 == 0
| return false; | ||
| } | ||
| return true; | ||
| } |
There was a problem hiding this comment.
This will throw NoSuchElementException when no even numbers exist, but the message won't match the required format. Use .orElseThrow(() -> new RuntimeException("Can't get min value from list: " + numbers))
|
|
||
| @Override | ||
| public boolean test(Candidate c) { | ||
| if (c.getAge() < 35) { |
There was a problem hiding this comment.
Checklist item #8: Use constants instead of magic numbers/strings. Define: private static final int MIN_AGE = 35; and private static final String UKRAINIAN_NATIONALITY = "Ukrainian"; and private static final int MIN_YEARS_IN_UKRAINE = 10;
| if (!c.isAllowedToVote()) { | ||
| return false; | ||
| } | ||
| if (!c.getNationality().equals("Ukrainian")) { |
There was a problem hiding this comment.
Checklist item #8: Magic string should use constant. Replace with UKRAINIAN_NATIONALITY constant.
| return false; | ||
| } | ||
| String[] years = c.getPeriodsInUkr().split("-"); | ||
| if (Integer.parseInt(years[1]) - Integer.parseInt(years[0]) < 10) { |
There was a problem hiding this comment.
Checklist item #8: Magic number 10 should use MIN_YEARS_IN_UKRAINE constant.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
The solution has made excellent progress fixing the major functional bugs from previous reviews. However, two checklist violations remain that must be addressed before approval:
-
CHECKLIST #5 Violations (CRITICAL): Three methods still use
==for Sex enum comparison instead of.equals():selectMenByAge()in Task 3getWorkablePeople()in Task 4getCatsNames()in Task 5
-
Wrong Exception Type (CRITICAL):
findMinEvenNumber()throwsIllegalArgumentExceptioninstead of the requiredRuntimeException.
These are explicit checklist violations marked as high/medium priority and prevent full compliance with the task requirements. Please fix the enum comparisons to use .equals() method and change the exception to RuntimeException.
✨ 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 peopleList.stream() | ||
| .filter(p -> p.getAge() >= fromAge && p.getAge() <= toAge |
There was a problem hiding this comment.
Use .equals() instead of == for Sex enum comparison as per [CHECKLIST #5]
| return peopleList.stream() | ||
| .filter(p -> p.getSex() == Person.Sex.MAN |
There was a problem hiding this comment.
Use .equals() instead of == for Sex enum comparison as per [CHECKLIST #5]
| public List<String> getCatsNames(List<Person> peopleList, int femaleAge) { | ||
| return Collections.emptyList(); | ||
| return peopleList.stream() | ||
| .filter(p -> p.getSex() == Sex.WOMAN && p.getAge() >= femaleAge) |
There was a problem hiding this comment.
Use .equals() instead of == for Sex enum comparison as per [CHECKLIST #5]
| .mapToInt(Integer::parseInt) | ||
| .filter(n -> n % 2 == 0) | ||
| .min() | ||
| .orElseThrow(() -> new IllegalArgumentException( |
There was a problem hiding this comment.
Throw RuntimeException instead of IllegalArgumentException as required by the task description
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am approving this submission as an educational override to help you progress while learning. Critical issue to fix: In selectMenByAge(), getWorkablePeople(), and getCatsNames(), you're comparing the Sex enum with string literals like "MAN" and "WOMAN" instead of enum constants Sex.MAN and Sex.WOMAN. Since getSex() returns a Sex enum, comparing it to a string via .equals() will always return false, breaking all filtering logic. Change p.getSex().equals("MAN") to p.getSex().equals(Sex.MAN) and similarly for WOMAN. Additionally, there's an unused import at line 10 (import model.Person.Sex;) that should be removed to pass Checkstyle. You handled Tasks 1, 2, and 6 correctly—great job on proper exception handling and using constants for magic values! These enum comparison fixes will bring your code to full functionality.
✨ 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 List<Person> selectMenByAge(List<Person> peopleList, int fromAge, int toAge) { | ||
| return Collections.emptyList(); | ||
| return peopleList.stream() | ||
| .filter(p -> p.getAge() >= fromAge && p.getAge() <= toAge |
There was a problem hiding this comment.
Comparing enum with string literal "MAN" will always return false since getSex() returns Sex enum (Sex.MAN). Use p.getSex().equals(Sex.MAN) instead of p.getSex().equals("MAN")
| int maleToAge, List<Person> peopleList) { | ||
| return Collections.emptyList(); | ||
| return peopleList.stream() | ||
| .filter(p -> p.getSex().equals("MAN") |
There was a problem hiding this comment.
Comparing enum with string literal "MAN" will always return false since getSex() returns Sex enum. Use p.getSex().equals(Sex.MAN) instead
| public List<String> getCatsNames(List<Person> peopleList, int femaleAge) { | ||
| return Collections.emptyList(); | ||
| return peopleList.stream() | ||
| .filter(p -> p.getSex().equals("WOMAN") && p.getAge() >= femaleAge) |
There was a problem hiding this comment.
Comparing enum with string literal "WOMAN" will always return false since getSex() returns Sex enum. Use p.getSex().equals(Sex.WOMAN) instead
|
|
||
| @Override | ||
| public boolean test(Candidate c) { | ||
| if (c.getAge() < MIN_AGE) { |
There was a problem hiding this comment.
don't use just letter for naming
| if (c.getAge() < MIN_AGE) { | |
| if (candidate.getAge() < MIN_AGE) { |
| .filter(p -> p.getSex().equals(Sex.MAN) | ||
| ? (p.getAge() >= fromAge && p.getAge() <= maleToAge) | ||
| : p.getAge() >= fromAge && p.getAge() <= femaleToAge) | ||
| .collect(Collectors.toList()); |
There was a problem hiding this comment.
same for other places
| .collect(Collectors.toList()); | |
| .toList(); |
| return Collections.emptyList(); | ||
| CandidateValidator validator = new CandidateValidator(); | ||
| return candidates.stream() | ||
| .filter(c -> validator.test(c)) |
There was a problem hiding this comment.
| .filter(c -> validator.test(c)) | |
| .filter(validator) |
| CandidateValidator validator = new CandidateValidator(); | ||
| return candidates.stream() | ||
| .filter(c -> validator.test(c)) | ||
| .map(c -> c.getName()) |
There was a problem hiding this comment.
| .map(c -> c.getName()) | |
| .map(Candidate::getName) |
|
|
||
| @Override | ||
| public boolean test(Candidate c) { | ||
| if (c.getAge() < MIN_AGE) { |
There was a problem hiding this comment.
could you simplify your solution with logical operators instead of using a lot of if ?
No description provided.