Uploaded image for project: 'Commons Collections'
  1. Commons Collections
  2. COLLECTIONS-111

IteratorChain skips over elements in iterator

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Closed
    • Major
    • Resolution: Cannot Reproduce
    • 3.1
    • None
    • Iterator
    • None
    • Operating System: Windows XP
      Platform: PC

    • 38341

    Description

      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.

      Attachments

        Activity

          People

            Unassigned Unassigned
            jo@jogiles.co.nz Jonathan Giles
            Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

              Created:
              Updated:
              Resolved: