Skip to content

completed all tasks#1396

Open
re9en wants to merge 4 commits into
mate-academy:mainfrom
re9en:main
Open

completed all tasks#1396
re9en wants to merge 4 commits into
mate-academy:mainfrom
re9en:main

Conversation

@re9en

@re9en re9en commented Apr 13, 2026

Copy link
Copy Markdown

No description provided.

@mateacademy-ai-mentor mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 findMinEvenNumber in StreamPractice.java, you split the input string and immediately call Integer.parseInt on each token; for inputs like "0, 22, 7" the tokens contain leading spaces and will throw NumberFormatException. Trim each token before parsing (e.g., .map(String::trim) or Integer.parseInt(token.trim())) so these inputs work as required.
  • In selectMenByAge in StreamPractice.java, the lower age bound uses person.getAge() > fromAge, which wrongly excludes candidates whose age is exactly fromAge; the requirement is a fully inclusive range, so the comparison must be >= fromAge to satisfy the spec.
  • In CandidateValidator.java, the literals 35 (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.java should use == instead of .equals() for Person.Sex values (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 before model.* imports, add braces to all single-line if statements in CandidateValidator.java (around lines 11, 13, 15), insert a blank line before the method reported around line 53 in StreamPractice.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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +22 to +23
.flatMap(s -> Arrays.stream(s.split(",")))
.map(Integer::parseInt)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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))

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Prefer using == to compare Enum values rather than .equals(). Use person.getSex() == Person.Sex.WOMAN instead of equals(...).

Comment on lines +22 to 23
}
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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).

Comment on lines +11 to +21
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Review Summary

I am requesting changes because there are still two critical issues that can break functionality and violate the explicit checklist requirements.

  1. In src/main/java/practice/StreamPractice.java, in findMinEvenNumber, you split the input with something like s.trim().split(",") and then call Integer.parseInt on each token without trimming those individual tokens; for inputs such as "0, 22, 7" this produces tokens like " 22" and will throw NumberFormatException instead 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.
  2. In src/main/java/practice/CandidateValidator.java, the predicate currently uses hard-coded literals like 35, "Ukrainian", and 10 directly in the logic; the checklist explicitly requires replacing such magic numbers and strings with named constants in CandidateValidator. Please introduce private static final constants (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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example


String[] years = candidate.getPeriodsInUkr().split("-");
int firstYear = Integer.parseInt(years[0]);
int lastYear = Integer.parseInt(years[1]);

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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) ).

Comment on lines +10 to +26
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;

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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.

Comment on lines +24 to +25
.flatMap(s -> Arrays.stream(s.trim().split(",")))
.map(Integer::parseInt)

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 mateacademy-ai-mentor left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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! ✨

Footnotes

  1. Rate AI review example

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants