public Object next() {
   Collection oldCollection = nextCollection;
   nextCollection = null;
   while (nodeIterator.hasNext()) {
     NodeProxy p = (NodeProxy) nodeIterator.next();
     if (!p.getDocument().getCollection().equals(oldCollection)) {
       nextCollection = p.getDocument().getCollection();
       break;
     }
   }
   return oldCollection;
 }
 CollectionIterator() {
   if (nodeIterator.hasNext()) {
     NodeProxy p = (NodeProxy) nodeIterator.next();
     nextCollection = p.getDocument().getCollection();
   }
 }