-
Notifications
You must be signed in to change notification settings - Fork 51
part 1 ,part 2, part 3 LambdaExercise are done ( Yuriy Korovko) #60
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?
Conversation
List<Person> actualPersonList = employeeList.stream() | ||
.filter(employee -> employee.getJobHistory().stream() | ||
.map(JobHistoryEntry::getEmployer) | ||
.anyMatch(emp -> emp.equalsIgnoreCase("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.
You can use method reference here "epam"::equalsIgnoreCase
} | ||
} | ||
} | ||
assertEquals(actualPersonList.size(), expectedPersonList.size()); |
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 compare collections. assertEquals(actualPersonList, expectedPersonList)
You can use Set
s to ignore order.
// TODO all persons with first experience in epam | ||
final List<Employee> employeeList = Generator.generateEmployeeList(); | ||
List<Person> epamEmployees = employeeList.stream() | ||
.filter(e -> e.getJobHistory().get(0).getEmployer().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 fails on empty collections. Use limit(1)
.
final Predicate<String> isJohnString = null; // TODO using method reference check that "John" equals string parameter | ||
final Predicate<String> | ||
isJohnString = | ||
Objects::nonNull; // TODO using method reference check that "John" equals string parameter |
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.
Incorrect.
final List<JobHistoryEntry> jobHistoryEntries = null; // TODO | ||
final List<JobHistoryEntry> | ||
jobHistoryEntries = | ||
employees.stream().flatMap(employee -> employee.getJobHistory().stream()).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.
Reformat code.
There should be a single action per line.
.map(...)
.flatMap(...)
.filter(...)
.collect(...)
final Map<Person, Integer> | ||
personDuration = | ||
employees.stream() | ||
.collect(Collectors.toMap(Employee::getPerson, e -> sumAllPersonDurations(e).getDuration())); |
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 could use flatMap(...).collect(grouppingBy(..., summingInt(...)))
@@ -57,7 +57,7 @@ public void getEmployeesStartedFromEpam() { | |||
// TODO all persons with first experience in epam | |||
final List<Employee> employeeList = Generator.generateEmployeeList(); | |||
List<Person> epamEmployees = employeeList.stream() | |||
.filter(e -> e.getJobHistory().get(0).getEmployer().equals("epam")) | |||
.filter(e -> e.getJobHistory().stream().limit(1).collect(toList()).get(0).getEmployer().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.
It's not better.
Use limit(1).anyMatch
No description provided.