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

added implementation for StreamPractice and CandidateValidator #925

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

Conversation

vadymhrnk
Copy link

No description provided.

//write your code here
import java.util.function.Predicate;
import model.Candidate;

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.

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.

.filter(i -> i % 2 == 0)
.min()
.orElseThrow(() -> new RuntimeException(
NO_SUCH_DATA_MESSAGE + Collectors.toList()));

Choose a reason for hiding this comment

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

Comment on lines 39 to 41
.filter(p -> p.getSex().equals(Person.Sex.MAN))
.filter(p -> p.getAge() >= fromAge)
.filter(p -> p.getAge() <= toAge)

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

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

Choose a reason for hiding this comment

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

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

Comment on lines 40 to 41
.filter(p -> p.getAge() >= fromAge)
.filter(p -> p.getAge() <= toAge)

Choose a reason for hiding this comment

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

Double getAge().

Comment on lines 48 to 51
.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());

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.

Comment on lines 56 to 57
.filter(p -> p.getSex().equals(Person.Sex.WOMAN))
.filter(p -> p.getAge() >= femaleAge)

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

Choose a reason for hiding this comment

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

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

.filter(candidateValidator)
.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.

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

Comment on lines 30 to 31
.map(i -> (i % 2 == 1) ? numbers.get(i) - 1 : numbers.get(i))
.filter(num -> num % 2 != 0)

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.

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.

4 participants