Author: centic
Date: Sun Jul  7 05:03:15 2024
New Revision: 1918982

URL: http://svn.apache.org/viewvc?rev=1918982&view=rev
Log:
HSSFWorkbook.getSheet(): Return first found sheet

We do not need to loop over all sheets always but should
be able to return the first found sheet.

This may change semantics for cases where there are
multiple sheets where name only differs in case, but
the JavaDoc did not state which one will be returned.

All three implementations (HSSF, XSSF, SXSSF)
now behave the same way.

Closes #653

Modified:
    
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
    
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
    poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java

Modified: 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java?rev=1918982&r1=1918981&r2=1918982&view=diff
==============================================================================
--- 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
 (original)
+++ 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/streaming/SXSSFWorkbook.java
 Sun Jul  7 05:03:15 2024
@@ -808,6 +808,9 @@ public class SXSSFWorkbook implements Wo
     /**
      * Get sheet with the given name
      *
+     * If there are multiple matches, the first sheet from the list
+     * of sheets is returned.
+     *
      * @param name of the sheet
      * @return Sheet with the name provided or <code>null</code> if it does 
not exist
      */

Modified: 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java?rev=1918982&r1=1918981&r2=1918982&view=diff
==============================================================================
--- 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
 (original)
+++ 
poi/trunk/poi-ooxml/src/main/java/org/apache/poi/xssf/usermodel/XSSFWorkbook.java
 Sun Jul  7 05:03:15 2024
@@ -1208,6 +1208,9 @@ public class XSSFWorkbook extends POIXML
     /**
      * Get sheet with the given name (case insensitive match)
      *
+     * If there are multiple matches, the first sheet from the list
+     * of sheets is returned.
+     *
      * @param name of the sheet
      * @return XSSFSheet with the name provided or {@code null} if it does not 
exist
      */

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java?rev=1918982&r1=1918981&r2=1918982&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java 
(original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java 
Sun Jul  7 05:03:15 2024
@@ -1055,24 +1055,25 @@ public final class HSSFWorkbook extends
     }
 
     /**
-     * Get sheet with the given name (case insensitive match)
+     * Get sheet with the given name (case insensitive match).
+     *
+     * If there are multiple matches, the first sheet from the list
+     * of sheets is returned.
      *
      * @param name of the sheet
      * @return HSSFSheet with the name provided or {@code null} if it does not 
exist
      */
-
     @Override
     public HSSFSheet getSheet(String name) {
-        HSSFSheet retval = null;
-
         for (int k = 0; k < _sheets.size(); k++) {
             String sheetname = workbook.getSheetName(k);
 
             if (sheetname.equalsIgnoreCase(name)) {
-                retval = _sheets.get(k);
+                return _sheets.get(k);
             }
         }
-        return retval;
+
+        return null;
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscr...@poi.apache.org
For additional commands, e-mail: commits-h...@poi.apache.org

Reply via email to