Skip to content

Conversation

YuryKorovko
Copy link

No description provided.

List<Person> actualPersonList = employeeList.stream()
.filter(employee -> employee.getJobHistory().stream()
.map(JobHistoryEntry::getEmployer)
.anyMatch(emp -> emp.equalsIgnoreCase("epam"))

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());

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 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"))

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

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());

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()));

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"))

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

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