Method removal for Iterators

This commit is contained in:
Niket Agrawal 2023-10-20 18:43:27 +05:30
parent ce61cf5e7d
commit 63b435c097
1 changed files with 0 additions and 30 deletions

View File

@ -2,9 +2,7 @@ package com.baeldung.streams.firstmatchingelement;
import static org.junit.jupiter.api.Assertions.assertEquals;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.stream.IntStream;
import org.apache.commons.collections4.IterableUtils;
@ -28,34 +26,6 @@ public class FirstMatchingElementUnitTest {
assertEquals(1, index);
}
@Test
public void whenUsingIterator_thenFindFirstMatchingUserIndex() {
int index = -1;
Iterator<User> iterator = userList.iterator();
while (iterator.hasNext()) {
User user = iterator.next();
if (searchName.equals(user.getUserName())) {
index = userList.indexOf(user);
break;
}
}
assertEquals(1, index);
}
@Test
public void whenUsingListIterator_thenFindFirstMatchingUserIndex() {
int index = -1;
ListIterator<User> listIterator = userList.listIterator();
while (listIterator.hasNext()) {
if (searchName.equals(listIterator.next()
.getUserName())) {
index = listIterator.previousIndex();
break;
}
}
assertEquals(1, index);
}
@Test
public void whenUsingIntStream_thenFindFirstMatchingUserIndex() {
int index = IntStream.range(0, userList.size() - 1)