-
Notifications
You must be signed in to change notification settings - Fork 51
streams HW #55
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
base: master
Are you sure you want to change the base?
streams HW #55
Conversation
} | ||
List<Person> actual = employees.stream() | ||
.filter(e -> e.getJobHistory().stream() | ||
.map(JobHistoryEntry::getEmployer).anyMatch(employer -> employer.equals("epam"))) |
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.
Note that you could use .anyMatch("epam"::equals)
instead.
List<Person> expected = new ArrayList<>(); | ||
|
||
for (Employee e : employees) { | ||
if (e.getJobHistory().get(0).equals("epam")) |
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 get
- it throws an exception on empty collection.
Map<String, List<Person>> employeesIndex = getEmployees().stream() | ||
.map(e -> new PersonEmployerDuration( | ||
e.getPerson(), | ||
e.getJobHistory().get(0).getEmployer())) |
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 get
.
final Map<Key, List<Value>> keyValuesMap1 = valueMap1.entrySet().stream() | ||
.collect(toMap(e -> keyMap1.get(e.getKey()), | ||
Map.Entry::getValue, | ||
(values, values2) -> { |
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 can't get collision here. no need in this parameter.
|
||
final Map<Key, List<Value>> keyValuesMap2 = valuesMap2 | ||
.entrySet().stream() | ||
.collect(toMap(e->keyMap2.get(e.getKey()), |
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 groupingBy
instead.
values.addAll(values2); | ||
return values; | ||
})); | ||
Map.Entry::getValue)); |
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.
Actually you may need conflict resolver here for null
keys.
No description provided.