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 #916

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

Conversation

YevheniiVlasenko
Copy link

No description provided.

Comment on lines 10 to 16
&& candidate.getAge() >= 35
&& candidate.getNationality().equals("Ukrainian")) {
int startYear = Integer.parseInt(
candidate.getPeriodsInUkr().split("-")[0]);
int endYear = Integer.parseInt(
candidate.getPeriodsInUkr().split("-")[1]);
return endYear - startYear >= 10;

Choose a reason for hiding this comment

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

Don`t use magic numbers

.filter(e -> e % 2 == 0)
.sorted()
.findFirst()
.orElseThrow(() -> new RuntimeException("Can't get min value from list: " + numbers));

Choose a reason for hiding this comment

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

Should be constant

})
.filter(number -> number % 2 != 0)
.average()
.orElseThrow(() -> new NoSuchElementException("Empty List provided"));

Choose a reason for hiding this comment

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

Should be constant

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!
A few comments need to be process.

Comment on lines 15 to 18
int startYear = Integer.parseInt(
candidate.getPeriodsInUkr().split("-")[0]);
int endYear = Integer.parseInt(
candidate.getPeriodsInUkr().split("-")[1]);

Choose a reason for hiding this comment

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

Let's make one variable for data that indicates how long a candidate is in country.
Also, it would be great to make constants for index numbers. Constant names will descript what item you take.
Double .split("-") call. Make constant for "-"

Copy link
Author

Choose a reason for hiding this comment

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

Sorry, refactored a little, but I can make it only in one barely readable line.
Could you please make a suggestion?

public int findMinEvenNumber(List<String> numbers) {
return 0;
return numbers.stream()
.map(e -> e.split(","))

Choose a reason for hiding this comment

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

Let's not use one-letter names.

Choose a reason for hiding this comment

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

Make constant for comma.

Comment on lines 31 to 34
if (index % 2 != 0) {
return numbers.get(index) - 1;
}
return numbers.get(index);

Choose a reason for hiding this comment

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

I think we can reduce code by providing a ternary operator.

}
return numbers.get(index);
})
.filter(number -> number % 2 != 0)

Choose a reason for hiding this comment

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

Lets avoid duplication of code that checks odd/even number.

Copy link
Author

Choose a reason for hiding this comment

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

Also, need a suggestion here. Spent more than an hour on this

return Collections.emptyList();
return peopleList.stream()
.filter(person -> person.getAge() >= fromAge && person.getAge() <= toAge)
.filter(person -> person.getSex().name().equals("MAN"))

Choose a reason for hiding this comment

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

Let's use enum instead string literal.

public List<Person> selectMenByAge(List<Person> peopleList, int fromAge, int toAge) {
return Collections.emptyList();
return peopleList.stream()
.filter(person -> person.getAge() >= fromAge && person.getAge() <= toAge)

Choose a reason for hiding this comment

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

Double getAge method call.

Comment on lines 54 to 56
return person.getAge() >= fromAge && person.getAge() <= maleToAge;
}
return 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.

Make a variable for name.

Predicate<Person> isWorkable = new Predicate<Person>() {
@Override
public boolean test(Person person) {
if (person.getSex().name().equals("MAN")) {

Choose a reason for hiding this comment

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

enum

.map(e -> e.split(","))
.flatMap(Arrays::stream)
.map(Integer::parseInt)
.filter(e -> e % 2 == 0)

Choose a reason for hiding this comment

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

One-letter name

public List<Person> getWorkablePeople(int fromAge, int femaleToAge,
int maleToAge, List<Person> peopleList) {
return Collections.emptyList();
int maleToAge, List<Person> peopleList) {

Choose a reason for hiding this comment

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

Format that line of code.

Choose a reason for hiding this comment

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

I think 54 line should be positioned further to the right than it is now.
Like line 52 on the screen. Add tabs.
image

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 24 to 29
.filter(number -> number % 2 == 0)
.sorted()
.findFirst()
.orElseThrow(() -> new RuntimeException(NO_MIN_VALUE_EXCEPTION_MESSAGE + numbers));
}

Choose a reason for hiding this comment

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

Suggested change
.filter(number -> number % 2 == 0)
.sorted()
.findFirst()
.orElseThrow(() -> new RuntimeException(NO_MIN_VALUE_EXCEPTION_MESSAGE + numbers));
}
.filter(number -> !isOddNumber(number))
.sorted()
.findFirst()
.orElseThrow(() -> new RuntimeException(NO_MIN_VALUE_EXCEPTION_MESSAGE + numbers));
}
private static boolean isOddNumber(int number) {
return number % 2 != 0;
}

Comment on lines 44 to 48
int personAge = person.getAge();
;
return personAge >= fromAge
&& personAge <= toAge
&& person.getSex().equals(Sex.MAN);

Choose a reason for hiding this comment

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

Suggested change
int personAge = person.getAge();
;
return personAge >= fromAge
&& personAge <= toAge
&& person.getSex().equals(Sex.MAN);
int personAge = person.getAge();
return personAge >= fromAge
&& personAge <= toAge
&& Sex.MAN.equals(person.getSex());

It will avoid NPE.

public List<Person> getWorkablePeople(int fromAge, int femaleToAge,
int maleToAge, List<Person> peopleList) {
return Collections.emptyList();
int maleToAge, List<Person> peopleList) {

Choose a reason for hiding this comment

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

I think 54 line should be positioned further to the right than it is now.
Like line 52 on the screen. Add tabs.
image

int maleToAge, List<Person> peopleList) {
Predicate<Person> isWorkable = person -> {
int personAge = person.getAge();
if (person.getSex().equals(Sex.MAN)) {

Choose a reason for hiding this comment

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

Suggested change
if (person.getSex().equals(Sex.MAN)) {
if (Sex.MAN.equals(person.getSex())) {

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