Have iterating over rows and cells work with JDK 1.5 foreach loops through java.lang.Iterable

git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@618676 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Nick Burch 2008-02-05 15:41:37 +00:00
parent 7f4e502991
commit ccc4069b86
6 changed files with 45 additions and 7 deletions

View File

@ -476,6 +476,13 @@ public class HSSFRow
{
return new CellIterator();
}
/**
* Alias for {@link CellIterator} to allow
* foreach loops
*/
public Iterator iterator() {
return cellIterator();
}
private class CellIterator implements Iterator
{

View File

@ -715,11 +715,17 @@ public class HSSFSheet implements org.apache.poi.ss.usermodel.Sheet
* @return an iterator of the PHYSICAL rows. Meaning the 3rd element may not
* be the third row if say for instance the second row is undefined.
*/
public Iterator rowIterator()
{
return rows.values().iterator();
}
/**
* Alias for {@link #rowIterator()} to allow
* foreach loops
*/
public Iterator iterator() {
return rowIterator();
}
/**
* used internally in the API to get the low level Sheet record represented by this

View File

@ -17,9 +17,10 @@
package org.apache.poi.ss.usermodel;
import java.lang.Iterable;
import java.util.Iterator;
public interface Row {
public interface Row extends Iterable {
// used for collections
public final static int INITIAL_CAPACITY = 5;
@ -145,14 +146,19 @@ public interface Row {
float getHeightInPoints();
/**
* @return cell iterator of the physically defined cells. Note element 4 may
* @return Cell iterator of the physically defined cells. Note element 4 may
* actually be row cell depending on how many are defined!
*/
Iterator<Cell> cellIterator();
Iterator cellIterator();
/**
* Alias for {@link #cellIterator()} to allow
* foreach loops
*/
Iterator<Cell> iterator();
int compareTo(Object obj);
boolean equals(Object obj);
}
}

View File

@ -22,7 +22,7 @@ import java.util.Iterator;
import org.apache.poi.hssf.util.PaneInformation;
import org.apache.poi.hssf.util.Region;
public interface Sheet {
public interface Sheet extends Iterable {
/* Constants for margins */
public static final short LeftMargin = Sheet.LeftMargin;
@ -250,8 +250,13 @@ public interface Sheet {
* @return an iterator of the PHYSICAL rows. Meaning the 3rd element may not
* be the third row if say for instance the second row is undefined.
*/
Iterator rowIterator();
/**
* Alias for {@link #rowIterator()} to allow
* foreach loops
*/
Iterator iterator();
/**
* whether alternate expression evaluation is on

View File

@ -53,6 +53,13 @@ public class XSSFRow implements Row {
public Iterator<Cell> cellIterator() {
return cells.iterator();
}
/**
* Alias for {@link #cellIterator()} to allow
* foreach loops
*/
public Iterator<Cell> iterator() {
return cellIterator();
}
public int compareTo(Object obj) {
// TODO Auto-generated method stub

View File

@ -502,6 +502,13 @@ public class XSSFSheet implements Sheet {
public Iterator<Row> rowIterator() {
return rows.iterator();
}
/**
* Alias for {@link #rowIterator()} to
* allow foreach loops
*/
public Iterator<Row> iterator() {
return rowIterator();
}
public void setAlternativeExpression(boolean b) {
// TODO Auto-generated method stub