ppkarwasz commented on PR #628:
URL: 
https://github.com/apache/commons-collections/pull/628#issuecomment-3191169721

   Hi @JoergBudi,
   
   I think this PR is still worth pursuing, but we could narrow its scope to 
just collapsing `IteratorChain` trees, and handle the `Unmodifiable` aspect in 
a separate PR.
   
   For the unmodifiable part, I’ve experimented with the following approach:
   
   1. Introduce an `UnmodifiableConvertible` interface for classes that have an 
`Unmodifiable` equivalent:
   
       ```java
       public interface UnmodifiableConvertible {
       
           /**
            * Returns an unmodifiable version of this instance.
            * <p>
            * The returned object must implement {@link Unmodifiable} and 
preserve all
            * public types (classes and interfaces) of the original instance.
            * </p>
            *
            * @return an unmodifiable version of this instance
            */
           Unmodifiable toUnmodifiable();
       }
       ```
   
   2. Update all existing `Iterator` implementations to either:
   
      * implement `Unmodifiable` (if they already throw unconditionally on 
`remove()`), or
      * implement `UnmodifiableConvertible`.
   
   This change would touch a lot of lines, so I plan to submit it separately. 
It would however enable collapsing nested iterators when they are interleaved 
with `UnmodifiableIterator`.
   
   One open question: should `toUnmodifiable()` be allowed to return `this`, or 
should it always return a new instance?
   
   The term “unmodifiable” is a bit misleading here: these iterators still 
maintain internal mutable state; the restriction applies only to the `remove()` 
operation. That’s why I’m leaning toward having `toUnmodifiable()` always 
return a distinct “snapshot” reflecting the current state.
   
   For `IteratorChain`, however, that snapshot would still share the same 
underlying iterators. In that case, it might make sense to specify that once 
`toUnmodifiable()` is called, the original instance should no longer be used, 
which would make returning `this` acceptable.
   
   What do you think?
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: [email protected]

For queries about this service, please contact Infrastructure at:
[email protected]

Reply via email to