Skip to content

Finish README task#1407

Open
melnyk317 wants to merge 5 commits into
mate-academy:mainfrom
melnyk317:hw19
Open

Finish README task#1407
melnyk317 wants to merge 5 commits into
mate-academy:mainfrom
melnyk317:hw19

Conversation

@melnyk317

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

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

import model.Candidate;
import model.Cat;
import model.Person;

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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;
}

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Filter checks for odd numbers (n % 2 != 0) but task requires even numbers. Change to: n % 2 == 0

return false;
}
return true;
}

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

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

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

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 item #8: Magic number 10 should use MIN_YEARS_IN_UKRAINE constant.

@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

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:

  1. CHECKLIST #5 Violations (CRITICAL): Three methods still use == for Sex enum comparison instead of .equals():

    • selectMenByAge() in Task 3
    • getWorkablePeople() in Task 4
    • getCatsNames() in Task 5
  2. Wrong Exception Type (CRITICAL): findMinEvenNumber() throws IllegalArgumentException instead of the required RuntimeException.

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

Comment on lines +52 to +53
return peopleList.stream()
.filter(p -> p.getAge() >= fromAge && p.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.

Use .equals() instead of == for Sex enum comparison as per [CHECKLIST #5]

Comment on lines +70 to +71
return peopleList.stream()
.filter(p -> p.getSex() == 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.

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Use .equals() instead of == for Sex enum comparison as per [CHECKLIST #5]

.mapToInt(Integer::parseInt)
.filter(n -> n % 2 == 0)
.min()
.orElseThrow(() -> new IllegalArgumentException(

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Throw RuntimeException instead of IllegalArgumentException as required by the task description

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

  1. Rate AI review example

  2. Re-request AI review example

  3. Add AI review comments example

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

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)

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Comparing enum with string literal "WOMAN" will always return false since getSex() returns Sex enum. Use p.getSex().equals(Sex.WOMAN) instead

@Elena-Bruyako Elena-Bruyako 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.

see comments


@Override
public boolean test(Candidate c) {
if (c.getAge() < MIN_AGE) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

don't use just letter for naming

Suggested change
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());

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

same for other places

Suggested change
.collect(Collectors.toList());
.toList();

return Collections.emptyList();
CandidateValidator validator = new CandidateValidator();
return candidates.stream()
.filter(c -> validator.test(c))

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
.filter(c -> validator.test(c))
.filter(validator)

CandidateValidator validator = new CandidateValidator();
return candidates.stream()
.filter(c -> validator.test(c))
.map(c -> c.getName())

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Suggested change
.map(c -> c.getName())
.map(Candidate::getName)


@Override
public boolean test(Candidate c) {
if (c.getAge() < MIN_AGE) {

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

could you simplify your solution with logical operators instead of using a lot of if ?

@melnyk317 melnyk317 requested a review from Elena-Bruyako May 13, 2026 18:43
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.

3 participants