From 321375583dc09763f11d4a7af2fd621e78dea547 Mon Sep 17 00:00:00 2001 From: Nick Burch Date: Tue, 5 Feb 2008 15:41:37 +0000 Subject: [PATCH] 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 --- .../org/apache/poi/hssf/usermodel/HSSFRow.java | 7 +++++++ .../org/apache/poi/hssf/usermodel/HSSFSheet.java | 8 +++++++- .../org/apache/poi/ss/usermodel/Row.java | 14 ++++++++++---- .../org/apache/poi/ss/usermodel/Sheet.java | 9 +++++++-- .../org/apache/poi/xssf/usermodel/XSSFRow.java | 7 +++++++ .../org/apache/poi/xssf/usermodel/XSSFSheet.java | 7 +++++++ 6 files changed, 45 insertions(+), 7 deletions(-) diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java b/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java index ce2bc605f..3ac5ae3a5 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFRow.java @@ -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 { diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java index 9fc0091ec..bb1f5794f 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java @@ -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 diff --git a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Row.java b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Row.java index ebf6b8928..b0b12cd25 100644 --- a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Row.java +++ b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Row.java @@ -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 cellIterator(); - Iterator cellIterator(); + /** + * Alias for {@link #cellIterator()} to allow + * foreach loops + */ + Iterator iterator(); int compareTo(Object obj); boolean equals(Object obj); -} \ No newline at end of file +} diff --git a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java index df06129fd..baa1055ad 100644 --- a/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java +++ b/src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java @@ -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 diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java index 6de47db42..0d155502e 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java @@ -53,6 +53,13 @@ public class XSSFRow implements Row { public Iterator cellIterator() { return cells.iterator(); } + /** + * Alias for {@link #cellIterator()} to allow + * foreach loops + */ + public Iterator iterator() { + return cellIterator(); + } public int compareTo(Object obj) { // TODO Auto-generated method stub diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java index b9779fbdc..02a192716 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java @@ -502,6 +502,13 @@ public class XSSFSheet implements Sheet { public Iterator rowIterator() { return rows.iterator(); } + /** + * Alias for {@link #rowIterator()} to + * allow foreach loops + */ + public Iterator iterator() { + return rowIterator(); + } public void setAlternativeExpression(boolean b) { // TODO Auto-generated method stub