]> source.dussan.org Git - poi.git/commitdiff
Have iterating over rows and cells work with JDK 1.5 foreach loops through java.lang...
authorNick Burch <nick@apache.org>
Tue, 5 Feb 2008 15:41:37 +0000 (15:41 +0000)
committerNick Burch <nick@apache.org>
Tue, 5 Feb 2008 15:41:37 +0000 (15:41 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/branches/ooxml@618676 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/usermodel/HSSFRow.java
src/java/org/apache/poi/hssf/usermodel/HSSFSheet.java
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Row.java
src/ooxml/interfaces-jdk15/org/apache/poi/ss/usermodel/Sheet.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFRow.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFSheet.java

index ce2bc605fb804df3a0b9830b69c52b57a19f51fe..3ac5ae3a5bb005aa96b7885466856de21d453f7e 100644 (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
     {
index 9fc0091ec47d744b9e6ecf27d98912995acf07f1..bb1f5794fdf8c6802cda44a8a4b01d59fa1f640a 100644 (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
index ebf6b8928124c5c1188271eccb8a2a3714473f8d..b0b12cd25d572936ace123991b9f047b550d4b71 100644 (file)
 
 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);
 
-}
\ No newline at end of file
+}
index df06129fd1796d98ef2ed11045d8bd3d1c9b5ec4..baa1055ad6161561cb4ec2898d2805968790b17b 100644 (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
index 6de47db42112f9b1b2dee98f402c0dbb3a3a24d0..0d155502ec0e1e314110916c158c0987d2bf9099 100644 (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
index b9779fbdc708f6839e3feec30d0d343082d98549..02a192716aa059e695611fff67781097b48eba3a 100644 (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