completed all tasks#1396
Conversation
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because there are a couple of functional bugs and explicit checklist violations that would cause tests and style checks to fail.
Critical issues to fix:
- In
findMinEvenNumberinStreamPractice.java, you split the input string and immediately callInteger.parseInton each token; for inputs like"0, 22, 7"the tokens contain leading spaces and will throwNumberFormatException. Trim each token before parsing (e.g.,.map(String::trim)orInteger.parseInt(token.trim())) so these inputs work as required. - In
selectMenByAgeinStreamPractice.java, the lower age bound usesperson.getAge() > fromAge, which wrongly excludes candidates whose age is exactlyfromAge; the requirement is a fully inclusive range, so the comparison must be>= fromAgeto satisfy the spec. - In
CandidateValidator.java, the literals35(minimum age),10(required years in Ukraine), and"Ukrainian"are used directly; the checklist explicitly requires replacing these magic values with named constants in this class (e.g.,MIN_AGE,REQUIRED_YEARS_IN_UKRAINE,REQUIRED_NATIONALITY).
Other required and style-related fixes:
- Enum comparisons in
StreamPractice.javashould use==instead of.equals()forPerson.Sexvalues (e.g.,p.getSex() == Person.Sex.MAN/Person.Sex.WOMAN), as highlighted in the comments and checklist. - Checkstyle is currently failing: avoid
java.util.*star imports, fix import ordering and blank lines beforemodel.*imports, add braces to all single-lineifstatements inCandidateValidator.java(around lines 11, 13, 15), insert a blank line before the method reported around line 53 inStreamPractice.java, and break any lines longer than 100 characters (around lines 73, 74, 85).
Your use of the Stream API and the general structure of the tasks is good, and once you address these specific issues your solution should fully meet both the functional and checklist requirements.
✨ 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
| .flatMap(s -> Arrays.stream(s.split(","))) | ||
| .map(Integer::parseInt) |
There was a problem hiding this comment.
findMinEvenNumber splits tokens but does not trim them before parsing. Inputs like "0, 22, 7" will produce tokens with leading spaces and Integer.parseInt(...) will throw NumberFormatException. Trim tokens (for example map each token to Integer.parseInt(token.trim()) or insert a .map(String::trim) before parsing).
| return Collections.emptyList(); | ||
| return peopleList.stream() | ||
| .filter(p -> p.getSex().equals(Person.Sex.MAN)) | ||
| .filter(person -> person.getAge() > fromAge && person.getAge() <= toAge) |
There was a problem hiding this comment.
The age comparison here is wrong for inclusive bounds. The requirement is fromAge to toAge inclusively, but the code uses person.getAge() > fromAge which excludes fromAge. Use >= fromAge.
| import java.util.stream.Collectors; | ||
| import java.util.stream.IntStream; | ||
|
|
||
| import model.Candidate; |
There was a problem hiding this comment.
Checklist requires using constants instead of magic numbers/strings in CandidateValidator. Extract literals like 35 (min age), 10 (required years in Ukraine) and "Ukrainian" into named constants in this class for readability and maintainability.
| public List<Person> selectMenByAge(List<Person> peopleList, int fromAge, int toAge) { | ||
| return Collections.emptyList(); | ||
| return peopleList.stream() | ||
| .filter(p -> p.getSex().equals(Person.Sex.MAN)) |
There was a problem hiding this comment.
Prefer using == to compare Enum values rather than .equals(). Use p.getSex() == Person.Sex.MAN instead of equals(...).
| int maleToAge, List<Person> peopleList) { | ||
| return Collections.emptyList(); | ||
| return peopleList.stream() | ||
| .filter(p -> (p.getSex().equals(Person.Sex.WOMAN) && p.getAge() >= fromAge && p.getAge() <= femaleToAge) |
There was a problem hiding this comment.
Prefer using == to compare Enum values rather than .equals(). Use p.getSex() == Person.Sex.WOMAN instead of equals(...) in this combined filter.
| public List<String> getCatsNames(List<Person> peopleList, int femaleAge) { | ||
| return Collections.emptyList(); | ||
| return peopleList.stream() | ||
| .filter(person -> person.getSex().equals(Person.Sex.WOMAN) && person.getAge() >= femaleAge) |
There was a problem hiding this comment.
Prefer using == to compare Enum values rather than .equals(). Use person.getSex() == Person.Sex.WOMAN instead of equals(...).
| } | ||
| } |
There was a problem hiding this comment.
You're splitting tokens and immediately calling Integer.parseInt. The task example shows inputs like {"5,30,100", "0, 22, 7", ...} which include spaces after commas — Integer.parseInt will throw for tokens with leading/trailing spaces. Trim tokens before parsing (e.g. Arrays.stream(s.split(",")).map(String::trim) or trim in the map).
| if (candidate.getAge() < 35) return false; | ||
|
|
||
| if (!candidate.isAllowedToVote()) return false; | ||
|
|
||
| if (!"Ukrainian".equals(candidate.getNationality())) return false; | ||
|
|
||
| String[] years = candidate.getPeriodsInUkr().split("-"); | ||
| int firstYear = Integer.parseInt(years[0]); | ||
| int lastYear = Integer.parseInt(years[1]); | ||
|
|
||
| return (lastYear - firstYear) >= 10; |
There was a problem hiding this comment.
This class uses literal numbers/strings (35, 10, "Ukrainian"). The checklist requires using constants in CandidateValidator:
"#### Use constants
Magic numbers and strings decrease code readability, let's avoid it and use constants in
class CandidateValidator".
Extract these values to named constants (e.g. MIN_AGE, REQUIRED_NATIONALITY, REQUIRED_YEARS) to improve readability and satisfy the checklist.
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
I am requesting changes because there are still two critical issues that can break functionality and violate the explicit checklist requirements.
- In
src/main/java/practice/StreamPractice.java, infindMinEvenNumber, you split the input with something likes.trim().split(",")and then callInteger.parseInton each token without trimming those individual tokens; for inputs such as"0, 22, 7"this produces tokens like" 22"and will throwNumberFormatExceptioninstead of returning the correct minimum even value. You should ensure each token is trimmed before parsing, for example by adding.map(String::trim)after the split (or otherwise trimming each token in the stream pipeline) so that all valid inputs, including those with spaces, are handled safely. - In
src/main/java/practice/CandidateValidator.java, the predicate currently uses hard-coded literals like35,"Ukrainian", and10directly in the logic; the checklist explicitly requires replacing such magic numbers and strings with named constants inCandidateValidator. Please introduceprivate static finalconstants (e.g.,MIN_AGE,REQUIRED_NATIONALITY,REQUIRED_YEARS_IN_UKRAINE) and use them in your conditions so the code is clearer and the checklist is satisfied.
Once you address the token-trimming issue in findMinEvenNumber and replace the magic literals with constants in CandidateValidator, the rest of your stream logic and candidate validation approach should pass the tests and align well with the task requirements—your overall use of the Stream API and predicates is already solid, so these are focused, fixable improvements.
✨ 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
|
|
||
| String[] years = candidate.getPeriodsInUkr().split("-"); | ||
| int firstYear = Integer.parseInt(years[0]); | ||
| int lastYear = Integer.parseInt(years[1]); |
There was a problem hiding this comment.
In findMinEvenNumber you call Arrays.stream(s.trim().split(",")) and then Integer.parseInt on each token. Trimming the whole input string doesn't remove leading spaces inside tokens (e.g. "0, 22, 7" → tokens like " 22"). This will cause NumberFormatException. Trim each token before parsing (for example: .flatMap(s -> Arrays.stream(s.split(","))).map(String::trim).map(Integer::parseInt) ).
| if (candidate.getAge() < 35) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!candidate.isAllowedToVote()) { | ||
| return false; | ||
| } | ||
|
|
||
| if (!"Ukrainian".equals(candidate.getNationality())) { | ||
| return false; | ||
| } | ||
|
|
||
| String[] years = candidate.getPeriodsInUkr().split("-"); | ||
| int firstYear = Integer.parseInt(years[0]); | ||
| int lastYear = Integer.parseInt(years[1]); | ||
|
|
||
| return (lastYear - firstYear) >= 10; |
There was a problem hiding this comment.
This class uses hard-coded magic values. The checklist requires: "Use constants Magic numbers and strings decrease code readability, let's avoid it and use constants in class CandidateValidator". Replace literals (age 35, nationality "Ukrainian", required years 10) with private static final constants in CandidateValidator (for example MIN_AGE, REQUIRED_NATIONALITY, REQUIRED_YEARS_IN_UKRAINE) and use them in the comparisons.
| .flatMap(s -> Arrays.stream(s.trim().split(","))) | ||
| .map(Integer::parseInt) |
There was a problem hiding this comment.
In findMinEvenNumber you call Integer.parseInt on tokens that may contain leading spaces. Splitting with s.trim().split(",") trims the whole string but not each token, so tokens like " 22" will cause NumberFormatException. Trim each token before parsing (for example: split then .map(String::trim) before Integer.parseInt, or trim each token inside the flatMap).
mateacademy-ai-mentor
left a comment
There was a problem hiding this comment.
Review Summary
Your solution is approved and functionally meets the task and checklist requirements, with all main behaviors implemented via the Stream API and exceptions handled as specified. This is an educational override approval to help you progress while learning, because there are still a couple of robustness issues worth improving. In CandidateValidator, around the code where you split periodsInUkr using split("-") and parse with Integer.parseInt, consider trimming each part and checking the split length before parsing so malformed input like "2002- 2015" or missing bounds does not cause unexpected NumberFormatException or ArrayIndexOutOfBoundsException. In StreamPractice.validateCandidates, using .stream().sorted().toList() ties you to newer Java versions; for better compatibility (e.g., Java 8/11) you could switch to .sorted().collect(Collectors.toList()) instead. Minor improvements: you might also add defensive null checks for candidate.getPeriodsInUkr() and candidate.getNationality() to make the validator more robust against incomplete data. Overall, your use of streams, predicates, constants instead of magic numbers, and precise exception messages is strong, and these suggested tweaks will help you write more resilient production-quality code.
✨ Please rate this review in the Platform's notification center1. I will be grateful for your feedback! ✨
No description provided.