-
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
added implementation for StreamPractice and CandidateValidator #925
base: main
Are you sure you want to change the base?
Conversation
//write your code here | ||
import java.util.function.Predicate; | ||
import model.Candidate; | ||
|
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 work. I don't have a special one.
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.
.filter(i -> i % 2 == 0) | ||
.min() | ||
.orElseThrow(() -> new RuntimeException( | ||
NO_SUCH_DATA_MESSAGE + 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.
.filter(p -> p.getSex().equals(Person.Sex.MAN)) | ||
.filter(p -> p.getAge() >= fromAge) | ||
.filter(p -> p.getAge() <= toAge) |
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.
Use one filter method.
Don't use one-letter names.
public int findMinEvenNumber(List<String> numbers) { | ||
return 0; | ||
return numbers.stream() | ||
.map(s -> s.split(REGEX_COMMA)) |
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.
Dont use one-letter names.
.filter(p -> p.getSex().equals(Person.Sex.MAN)) | ||
.filter(p -> p.getAge() >= fromAge) | ||
.filter(p -> p.getAge() <= toAge) | ||
.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.
.collect(Collectors.toList()); | |
.toList(); |
.filter(p -> p.getAge() >= fromAge) | ||
.filter(p -> p.getAge() <= toAge) |
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.
Double getAge()
.
.filter(p -> p.getAge() >= fromAge) | ||
.filter(p -> p.getSex().equals(Person.Sex.WOMAN) && p.getAge() <= femaleToAge | ||
|| p.getSex().equals(Person.Sex.MAN) && p.getAge() <= maleToAge) | ||
.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.
Don't use one-letter names.
Use one filter method call.
Make constants for reducing getSex() method call twice and getAge() method call four times.
Use Stream.toList().
If you have constant use Person.Sex.MAN.equals(p.getSex())
to avoid NPE.
.filter(p -> p.getSex().equals(Person.Sex.WOMAN)) | ||
.filter(p -> 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.
Use one filter method.
One letter names.
.map(Person::getCats) | ||
.flatMap(Collection::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.
.collect(Collectors.toList()); | |
.toList(); |
.filter(candidateValidator) | ||
.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.
.collect(Collectors.toList()); | |
.toList(); |
.map(i -> (i % 2 == 1) ? numbers.get(i) - 1 : numbers.get(i)) | ||
.filter(num -> num % 2 != 0) |
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.
Avoid duplication of code that checks even/odd numbers.
No description provided.