-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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
base: main
Are you sure you want to change the base?
Conversation
# Conflicts: # src/main/java/practice/StreamPractice.java
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good job! 👍
There was a problem hiding this 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.
return Integer.parseInt(periodLength[1]) | ||
- Integer.parseInt(periodLength[0]) >= MIN_PERIOD_OF_LIVING; |
There was a problem hiding this comment.
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.
return Integer.parseInt(periodLength[1]) | ||
- Integer.parseInt(periodLength[0]) >= MIN_PERIOD_OF_LIVING; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
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); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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()); |
There was a problem hiding this comment.
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) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
.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()); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
same
return person.getSex() == Person.Sex.MAN | ||
&& person.getAge() >= fromAge && person.getAge() <= maleToAge | ||
|| person.getSex() == Person.Sex.WOMAN | ||
&& person.getAge() >= fromAge && person.getAge() <= femaleToAge; |
There was a problem hiding this comment.
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
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good job.
No description provided.