Skip to content

Commit

Permalink
HSEARCH-1769 Make ChangesetList resilient to empty List<LuceneWork>
Browse files Browse the repository at this point in the history
  • Loading branch information
emmanuelbernard authored and Sanne committed Jan 9, 2015
1 parent fd28807 commit b11802b
Showing 1 changed file with 10 additions and 9 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.NoSuchElementException;

import org.hibernate.search.backend.LuceneWork;

Expand Down Expand Up @@ -69,21 +70,21 @@ public WorkIterator(Iterator<Changeset> iterator) {

@Override
public boolean hasNext() {
// advance the outer until we find a non empty current or we reach the end of the outer
// to work around empty LuceneWork lists being passed
while ( ! current.hasNext() && outerIterator.hasNext() ) {
current = outerIterator.next().getWorkListIterator();
}
return current.hasNext() || outerIterator.hasNext();
}

@Override
public LuceneWork next() {
if ( current.hasNext() ) {
//advance the inner loop only
return current.next();
}
else {
//advance outer loop first
Changeset next = outerIterator.next();
current = next.getWorkListIterator();
return current.next();
// force the position to an non empty current or the end of the flow
if ( ! hasNext() ) {
throw new NoSuchElementException( "Reached the end of the ChangesetList. Make sure to guard .next() with .hasNext()" );
}
return current.next();
}

@Override
Expand Down

0 comments on commit b11802b

Please sign in to comment.