Skip to content

Add implementation for UserServiceImpl#1

Merged
vitalibutnar merged 1 commit intomasterfrom
implementation_for_userServiceImpl
Oct 1, 2021
Merged

Add implementation for UserServiceImpl#1
vitalibutnar merged 1 commit intomasterfrom
implementation_for_userServiceImpl

Conversation

@vitalibutnar
Copy link
Copy Markdown
Owner

Add implementation for UserServiceImpl

public List<String> getFirstNamesReverseSorted(List<User> users) {
throw new UnsupportedOperationException("Not implemented");
return users.stream().
map(User::getFirstName).
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

There is a reversed() method in Comparator that could be used

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Thanks, it's a great idea

@Override
public double getAverageAgeForUsers(final List<User> users) {
throw new UnsupportedOperationException("Not implemented");
return users.stream().mapToDouble(User::getAge).average().orElse(-1d);
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

No need to add "d" to -1

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

ok, I'll fix

@Override
public String convertTo(final List<User> users, final String delimiter, final Function<User, String> mapFun) {
throw new UnsupportedOperationException("Not implemented");
return users.stream().map(mapFun).reduce((res, str) -> res += delimiter + str).orElse("");
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

could make it easier .collect(Collectors.joining(delimiter)) instead of reduce.

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

Yes, I've done it in extra homework but miss here

@Override
public Optional<String> getMostFrequentLastName(final List<User> users) {
throw new UnsupportedOperationException("Not implemented");
Map<String, Long> map = users.stream().map(User::getLastName).
Copy link
Copy Markdown

Choose a reason for hiding this comment

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

What if we have a list containing one user? should it return Optional.empty?
"optional of most frequent last name (if it encountered at least two times)"

Copy link
Copy Markdown
Owner Author

Choose a reason for hiding this comment

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

There is a logical error in condition

@vitalibutnar vitalibutnar force-pushed the implementation_for_userServiceImpl branch from 0542e18 to 6672cd1 Compare September 30, 2021 13:10
@vitalibutnar vitalibutnar merged commit 2c758ce into master Oct 1, 2021
@vitalibutnar vitalibutnar deleted the implementation_for_userServiceImpl branch October 1, 2021 06:18
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.

2 participants