part 1 ,part 2, part 3 LambdaExercise are done ( Yuriy Korovko)#60
Open
YuryKorovko wants to merge 5 commits intojava8-course:masterfrom
YuryKorovko:master
Open
part 1 ,part 2, part 3 LambdaExercise are done ( Yuriy Korovko)#60YuryKorovko wants to merge 5 commits intojava8-course:masterfrom YuryKorovko:master
YuryKorovko wants to merge 5 commits intojava8-course:masterfrom
YuryKorovko:master
Conversation
senia-psm
reviewed
Apr 18, 2017
| 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.
You can use method reference here "epam"::equalsIgnoreCase
| } | ||
| } | ||
| } | ||
| assertEquals(actualPersonList.size(), expectedPersonList.size()); |
There was a problem hiding this comment.
You can compare collections. assertEquals(actualPersonList, expectedPersonList)
You can use Sets 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.
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 |
senia-psm
reviewed
Apr 18, 2017
| 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.
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.
You could use flatMap(...).collect(grouppingBy(..., summingInt(...)))
added 2 commits
April 20, 2017 16:58
senia-psm
reviewed
Apr 20, 2017
| 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.
It's not better.
Use limit(1).anyMatch
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
No description provided.