Review Comment changes

This commit is contained in:
Niket Agrawal 2023-11-07 23:13:46 +05:30
parent 2f34022ded
commit 2628fe1eb0
1 changed files with 6 additions and 2 deletions

View File

@ -44,9 +44,13 @@ public class FirstMatchingElementUnitTest {
@Test
public void whenUsingTakeWhile_thenFindFirstMatchingUserIndex() {
int lastIndex = userList.size() - 1;
AtomicInteger counter = new AtomicInteger(-1);
int predicateIndex = userList.stream()
.takeWhile(user -> !(searchName.equals(user.getUserName())))
.mapToInt(userList::indexOf)
.takeWhile(user -> {
counter.getAndIncrement();
return !(searchName.equals(user.getUserName()));
})
.mapToInt(user -> counter.get())
.max()
.orElse(-1);