[ 
https://issues.apache.org/jira/browse/COLLECTIONS-309?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Thomas Neidhart resolved COLLECTIONS-309.
-----------------------------------------

    Resolution: Won't Fix

Directly using an externally provided collection/array in an class is always a 
bad idea. Locking the iterator would be not useful, as the provided list would 
be externally modifiable, leading to undefined behavior.

The usual good pattern is to copy the arguments to an internal collection, 
which is not much overhead but prevents any side-effects.

The current constructors already allow to provide a list as input, which 
entries will be added to the chain.
                
> IteratorChain should include factory methods for decorating iterator lists 
> and arrays into locked IteratorChain.
> ----------------------------------------------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-309
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-309
>             Project: Commons Collections
>          Issue Type: Improvement
>          Components: Iterator
>    Affects Versions: 3.2
>         Environment: n/a
>            Reporter: ori
>            Priority: Minor
>
> IteratorChain should not instantiate an ArrayList for every new instance.
> A private constructor taking a list should be added.
> Then we can add static factory methods for decorating a list of iterators to 
> produce a locked chain:
>     public static IteratorChain decorate( List iterators )
>     {
>         final IteratorChain chain = new IteratorChain( iterators );
>         chain.lockChain();
>         return chain;
>     }
>     private IteratorChain( List iteratorChain )
>     {
>         this.iteratorChain = iteratorChain;
>     }
>     public IteratorChain()
>     {
>         this( new ArrayList() );
>     }
> Some other observations:
> 1. There's a copy/paste mistake in the comment above the isLocked member 
> declaration (it says ComparatorChain is "locked" after the first time 
> compare(Object,Object) is called).
> 2. It's probably impossible to change now but the naming/semantics of 
> IteratorChain, ComparatorChain, and ChainedTransformer should all be 
> identical. There's a lot of duplicated functionality among these 3 classes.

--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators
For more information on JIRA, see: http://www.atlassian.com/software/jira

Reply via email to