From 023f497842a9311d6c52fe2cd95756f85a9f8e13 Mon Sep 17 00:00:00 2001 From: Claude Warren Date: Mon, 21 Oct 2024 14:36:57 +0100 Subject: [PATCH] changes as per review --- .../iterators/ExtendedIterator.java | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/main/java/org/apache/commons/collections4/iterators/ExtendedIterator.java b/src/main/java/org/apache/commons/collections4/iterators/ExtendedIterator.java index b794958fb..7b6733543 100644 --- a/src/main/java/org/apache/commons/collections4/iterators/ExtendedIterator.java +++ b/src/main/java/org/apache/commons/collections4/iterators/ExtendedIterator.java @@ -26,18 +26,17 @@ import java.util.stream.Stream; /** - * A ExtendedIterator is an Iterator wrapping around a plain - * (or presented as plain) Iterator. The wrapping allows the usual - * operations found on streams (filtering, concatenating, mapping) to be done on an Iterator derived - * from some other source. It also provides convenience methods for common operations. + * Extends Iterator functionality to include operations commonly found on streams (e.g. filtering, concatenating, mapping). + * It also provides convenience methods for common operations. * @param The type of object returned from the iterator. + * @since 4.5.0-M3 */ public final class ExtendedIterator implements Iterator { /** * Set to true if this wrapping doesn't permit the use of * {@link #remove()}, otherwise removal is delegated to the base iterator. */ - private final boolean removeDenied; + private final boolean throwOnRemove; /** * Creates an ExtendedIterator wrapped round it, @@ -109,11 +108,11 @@ public final class ExtendedIterator implements Iterator { /** * Initialise this wrapping with the given base iterator and remove-control. * @param base the base iterator that this iterator wraps - * @param removeDenied true if .remove() must throw an exception + * @param throwOnRemove true if .remove() must throw an exception */ - private ExtendedIterator(final Iterator base, final boolean removeDenied) { + private ExtendedIterator(final Iterator base, final boolean throwOnRemove) { this.base = base; - this.removeDenied = removeDenied; + this.throwOnRemove = throwOnRemove; } @Override @@ -133,7 +132,7 @@ public final class ExtendedIterator implements Iterator { @Override public void remove() { - if (removeDenied) { + if (throwOnRemove) { throw new UnsupportedOperationException(); } base.remove(); @@ -160,7 +159,7 @@ public final class ExtendedIterator implements Iterator { ((IteratorChain) base).addIterator(other); return this; } - return new ExtendedIterator(new IteratorChain(this.base, other), this.removeDenied); + return new ExtendedIterator(new IteratorChain(this.base, other), this.throwOnRemove); } /** @@ -170,7 +169,7 @@ public final class ExtendedIterator implements Iterator { * @return An iterator filtered by the predicate. */ public ExtendedIterator filter(final Predicate predicate) { - return new ExtendedIterator(new FilterIterator<>(this, predicate::test), this.removeDenied); + return new ExtendedIterator(new FilterIterator<>(this, predicate::test), this.throwOnRemove); } /**