Skip to content

Commit

Permalink
PDFBOX-5623: adjust next/hasNext as the index values aren't necessari…
Browse files Browse the repository at this point in the history
…ly sorted

git-svn-id: https://svn.apache.org/repos/asf/pdfbox/trunk@1911342 13f79535-47bb-0310-9956-ffa450edef68
  • Loading branch information
lehmi committed Jul 29, 2023
1 parent c165c11 commit a0e60ee
Showing 1 changed file with 5 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,6 @@ private static class ObjectNumbers implements Iterator<Long>
private int currentRange = 0;
private long currentEnd = 0;
private long currentNumber = 0;
private long maxValue = 0;

private ObjectNumbers(COSArray indexArray) throws IOException
{
Expand Down Expand Up @@ -209,7 +208,6 @@ private ObjectNumbers(COSArray indexArray) throws IOException
long sizeValue = ((COSInteger) base).longValue();
start[counter] = startValue;
end[counter] = startValue + sizeValue;
maxValue = Math.max(maxValue, end[counter]);
counter++;
}
currentNumber = start[0];
Expand All @@ -219,20 +217,20 @@ private ObjectNumbers(COSArray indexArray) throws IOException
@Override
public boolean hasNext()
{
return currentNumber < maxValue;
return currentRange < start.length || currentNumber < currentEnd;
}

@Override
public Long next()
{
if (currentNumber >= maxValue)
{
throw new NoSuchElementException();
}
if (currentNumber < currentEnd)
{
return currentNumber++;
}
if (currentRange >= start.length - 1)
{
throw new NoSuchElementException();
}
currentNumber = start[++currentRange];
currentEnd = end[currentRange];
return currentNumber++;
Expand Down

0 comments on commit a0e60ee

Please sign in to comment.