bug 40285: Corrected index of CellIterator. In addition made CelIterator obey the Iterator contract wrt exceptions.

git-svn-id: https://svn.apache.org/repos/asf/jakarta/poi/trunk@436986 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Jason Height 2006-08-25 22:24:47 +00:00
parent c371aa983d
commit 6759fe7790

View File

@ -28,6 +28,7 @@ import org.apache.poi.hssf.record.RowRecord;
import java.util.HashMap; import java.util.HashMap;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException;
/** /**
* High level representation of a row of a spreadsheet. * High level representation of a row of a spreadsheet.
@ -436,7 +437,8 @@ public class HSSFRow
private class CellIterator implements Iterator private class CellIterator implements Iterator
{ {
int thisId,nextId=0; int thisId=-1;
int nextId=-1;
public CellIterator() public CellIterator()
{ {
@ -448,6 +450,8 @@ public class HSSFRow
} }
public Object next() { public Object next() {
if (!hasNext())
throw new NoSuchElementException("At last element");
HSSFCell cell=cells[nextId]; HSSFCell cell=cells[nextId];
thisId=nextId; thisId=nextId;
findNext(); findNext();
@ -455,6 +459,8 @@ public class HSSFRow
} }
public void remove() { public void remove() {
if (thisId == -1)
throw new IllegalStateException("remove() called before next()");
cells[thisId]=null; cells[thisId]=null;
} }