commons-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Henri Yandell (JIRA)" <j...@apache.org>
Subject [jira] Commented: (COLLECTIONS-111) IteratorChain skips over elements in iterator
Date Tue, 11 Sep 2007 17:36:32 GMT

    [ https://issues.apache.org/jira/browse/COLLECTIONS-111?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel#action_12526533
] 

Henri Yandell commented on COLLECTIONS-111:
-------------------------------------------

Here's the 2.1.1 to trunk diff for that method:

********
     protected void updateCurrentIterator() {
         if (currentIterator == null) {
-            currentIterator = (Iterator) iteratorChain.get(0);
+            if (iteratorChain.isEmpty()) {
+                currentIterator = EmptyIterator.INSTANCE;
+            } else {
+                currentIterator = (Iterator) iteratorChain.get(0);
+            }
             // set last used iterator here, in case the user calls remove
             // before calling hasNext() or next() (although they shouldn't)
             lastUsedIterator = currentIterator;
-            return;
         }

-        if (currentIteratorIndex == (iteratorChain.size() - 1)) {
-            return;
-        }
-
-        while (currentIterator.hasNext() == false) {
-            ++currentIteratorIndex;
+        while (currentIterator.hasNext() == false && currentIteratorIndex < iteratorChain.size()
- 1) {
+            currentIteratorIndex++;
             currentIterator = (Iterator) iteratorChain.get(currentIteratorIndex);
-
-            if (currentIteratorIndex == (iteratorChain.size() - 1)) {
-                return;
-            }
         }
     }
***********

> IteratorChain skips over elements in iterator
> ---------------------------------------------
>
>                 Key: COLLECTIONS-111
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-111
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Iterator
>    Affects Versions: 3.1
>         Environment: Operating System: Windows XP
> Platform: PC
>            Reporter: Jonathan Giles
>             Fix For: 3.3
>
>
> Hi there,
> When using the IteratorChain class to add multiple iterators, it appears that
> using itChain.hasNext() and itChain.next() skips a number of elements in the
> iterator at each step.
> Given a single iterator of 7 elements, and using the following code:
> private IteratorChain buildIterator() {
> // this iterator contains the children of the current object only
> Iterator it = getChildren(p);
> 		
> // we use an IteratorChain to add multiple iterators together without the
> overhead of copying
> IteratorChain itChain = new IteratorChain(it);
> return itChain;
> }
> and then simply
> IteratorChain it = treeModel.getAllTreeNodes(obj);
> 	
> // FIXME this only prints one or two of the results, which is a bug!
> while (it.hasNext())
>     System.out.println(": " + it.next().getClass());
> I put in 7 elements, but only get 2 out - the 2nd and the last elements. It
> appears that through my debugging that the nextClause variable is updated even
> when the hasNext() function is called.
> Also, if I put 7 system.out.println statements, all elements are printed as normal.

-- 
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.


Mime
View raw message