code: private void initOrderedIterator()
     {
        if (orderedNodes != null)
        {
           return;
        }
        long time = 0;
        if (LOG.isDebugEnabled())
        {
           time = System.currentTimeMillis();
        }
        ScoreNode[][] nodes = (ScoreNode[][])scoreNodes.toArray(new ScoreNode[scoreNodes.size()][]);
  
        final Set<String> invalidIDs = new HashSet<String>(2);
  
        /** Cache for Nodes obtainer during the order (comparator work) */
        final Map<String, NodeData> lcache = new HashMap<String, NodeData>();
        do
        {
           if (invalidIDs.size() > 0)
           {
              // previous sort run was not successful -> remove failed uuids
              List<ScoreNode[]> tmp = new ArrayList<ScoreNode[]>();
              for (int i = 0; i < nodes.length; i++)
              {
                 if (!invalidIDs.contains(nodes[i][selectorIndex].getNodeId()))
                 {
                    tmp.add(nodes[i]);
                 }
              }
              nodes = (ScoreNode[][])tmp.toArray(new ScoreNode[tmp.size()][]);
              invalidIDs.clear();
           }
  
           try
           {
              // sort the uuids
              Arrays.sort(nodes, new ScoreNodeComparator(lcache, invalidIDs));
           }
           catch (SortFailedException e)
           {
              if (LOG.isTraceEnabled())
              {
                 LOG.trace("An exception occurred: " + e.getMessage());
              }
           }
  
        }
        while (invalidIDs.size() > 0);
  
        if (LOG.isDebugEnabled())
        {
           LOG.debug("" + nodes.length + " node(s) ordered in " + (System.currentTimeMillis() - time) + " ms");
        }
  
        orderedNodes = new ScoreNodeIteratorImpl(nodes);
     }
docs: Initializes the NodeIterator in document order