Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

implemented all methods of StreamPractice according to task #922

Open
wants to merge 5 commits into
base: main
Choose a base branch
from

Conversation

Andriy-Hrynevetskyi
Copy link

No description provided.

Copy link

@DevIgork DevIgork left a comment

Choose a reason for hiding this comment

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

good job! 👍

Copy link

@bhdnchui bhdnchui left a comment

Choose a reason for hiding this comment

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

Good job, but a few comments need to be processed.

Comment on lines 25 to 26
return Integer.parseInt(periodLength[1])
- Integer.parseInt(periodLength[0]) >= MIN_PERIOD_OF_LIVING;

Choose a reason for hiding this comment

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

Let's make constant for indexes.

Comment on lines 25 to 26
return Integer.parseInt(periodLength[1])
- Integer.parseInt(periodLength[0]) >= MIN_PERIOD_OF_LIVING;

Choose a reason for hiding this comment

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

Suggested change
return Integer.parseInt(periodLength[1])
- Integer.parseInt(periodLength[0]) >= MIN_PERIOD_OF_LIVING;
int yearsInUkraine = Integer.parseInt(periodLength[1]) - Integer.parseInt(periodLength[0]);
return yearsInUkraine >= MIN_PERIOD_OF_LIVING;

}

private boolean hasTenYearsPeriodOfLivingInUkraine(String period) {
String[] periodLength = period.split(SPLIT_REGEX);

Choose a reason for hiding this comment

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

Try to find better name.

boolean isAllowedToVote = candidate.isAllowedToVote();
boolean isNationalityAllowed = candidate.getNationality().equals(REQUIRED_NATIONALITY);
boolean isLivingTenYearsInUkraine
= hasTenYearsPeriodOfLivingInUkraine(candidate.getPeriodsInUkr());

Choose a reason for hiding this comment

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

Can we simplify method name?

})
.filter(i -> i % 2 != 0)
.average()
.orElseThrow(NoSuchElementException::new);

Choose a reason for hiding this comment

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

If you need to throw exception when no result found after stream execution sometimes get()/getAsDouble() may help, try to google what does it do.

return Collections.emptyList();
return peopleList.stream()
.filter(p -> validatePerson(p, fromAge, maleToAge, femaleToAge))
.collect(Collectors.toList());

Choose a reason for hiding this comment

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

same

.filter(p -> p.getSex().equals(Person.Sex.WOMAN) && p.getAge() >= femaleAge)
.flatMap(p -> p.getCats().stream())
.map(Cat::getName)
.collect(Collectors.toList());

Choose a reason for hiding this comment

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

same

public List<String> getCatsNames(List<Person> peopleList, int femaleAge) {
return Collections.emptyList();
return peopleList.stream()
.filter(p -> p.getSex().equals(Person.Sex.WOMAN) && p.getAge() >= femaleAge)

Choose a reason for hiding this comment

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

Suggested change
.filter(p -> p.getSex().equals(Person.Sex.WOMAN) && p.getAge() >= femaleAge)
.filter(p -> Person.Sex.WOMAN.equals(p.getSex()) && p.getAge() >= femaleAge)

Plus, one-letter names

.filter(validator)
.map(Candidate::getName)
.sorted()
.collect(Collectors.toList());

Choose a reason for hiding this comment

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

same

Comment on lines 72 to 75
return person.getSex() == Person.Sex.MAN
&& person.getAge() >= fromAge && person.getAge() <= maleToAge
|| person.getSex() == Person.Sex.WOMAN
&& person.getAge() >= fromAge && person.getAge() <= femaleToAge;

Choose a reason for hiding this comment

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

You call getAge 4 times and getSex 2 times, avoid it.
Enum comparison.

# Conflicts:
#	src/main/java/practice/StreamPractice.java
Copy link

@bhdnchui bhdnchui left a comment

Choose a reason for hiding this comment

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

Good job.

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