Add FilterIterator.removeNext() #564
This commit is contained in:
parent
0b9ced0d8b
commit
2a0f86a94d
|
@ -59,6 +59,7 @@
|
|||
<action type="add" issue="COLLECTIONS-869" dev="ggregory" due-to="Gary Gregory">Add org.apache.commons.collections4.IteratorUtils.chainedIterator(Iterator<? extends Iterator<? extends E>>).</action>
|
||||
<action type="add" dev="ggregory" due-to="Peter De Maeyer" issue="COLLECTIONS-533">Add ArrayListValuedLinkedHashMap #560.</action>
|
||||
<action type="fix" dev="ggregory" due-to="Gary Gregory">Add missing test AbstractIteratorTest.testForEachRemaining().</action>
|
||||
<action type="fix" dev="ggregory" due-to="Gary Gregory, Claude Warren">Add FilterIterator.removeNext() #564.</action>
|
||||
<!-- UPDATE -->
|
||||
<action type="update" dev="ggregory" due-to="Gary Gregory">Bump org.apache.commons:commons-parent from 71 to 78 #534, #545, #550 #555, #566.</action>
|
||||
<action type="update" issue="COLLECTIONS-857" dev="ggregory" due-to="Claude Warren">Update bloom filter documentation #508.</action>
|
||||
|
|
|
@ -141,6 +141,18 @@ public class FilterIterator<E> implements Iterator<E> {
|
|||
iterator.remove();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the next item and removes it from the iterator.
|
||||
*
|
||||
* @return the next item from the iterator.
|
||||
* @since 4.5.0-M3
|
||||
*/
|
||||
public E removeNext() {
|
||||
final E result = next();
|
||||
remove();
|
||||
return result;
|
||||
}
|
||||
|
||||
private Predicate<? super E> safePredicate(final Predicate<? super E> predicate) {
|
||||
return predicate != null ? predicate : TruePredicate.truePredicate();
|
||||
}
|
||||
|
|
|
@ -172,6 +172,22 @@ public class FilterIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||
assertTrue(actual.isEmpty());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveNext() {
|
||||
final FilterIterator<E> iter = makeObject();
|
||||
final E i = iter.removeNext();
|
||||
assertFalse(list.contains(i));
|
||||
final List<E> actual = new ArrayList<>();
|
||||
iter.forEachRemaining(actual::add);
|
||||
assertEquals(list, actual);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRemoveNextEmpty() {
|
||||
final FilterIterator<E> empty = makeEmptyIterator();
|
||||
assertThrows(NoSuchElementException.class, empty::removeNext);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRepeatedHasNext() {
|
||||
for (int i = 0; i <= array.length; i++) {
|
||||
|
@ -188,7 +204,6 @@ public class FilterIteratorTest<E> extends AbstractIteratorTest<E> {
|
|||
verifyNoMoreElements();
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testReturnValues() {
|
||||
verifyElementsInPredicate(ArrayUtils.EMPTY_STRING_ARRAY);
|
||||
|
|
Loading…
Reference in New Issue