]> source.dussan.org Git - poi.git/commitdiff
pull out loop invariants, use List.indexOf to look up sheet index
authorJaven O'Neal <onealj@apache.org>
Fri, 20 Jan 2017 04:38:18 +0000 (04:38 +0000)
committerJaven O'Neal <onealj@apache.org>
Fri, 20 Jan 2017 04:38:18 +0000 (04:38 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1779560 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/hssf/model/InternalWorkbook.java
src/java/org/apache/poi/hssf/usermodel/HSSFWorkbook.java
src/java/org/apache/poi/ss/util/WorkbookUtil.java

index 023007d365aa272e1c86de42e0bd72b2a47741c8..063830d32725cb6de9c2a1a7a2ed6e9ebf75353f 100644 (file)
@@ -770,7 +770,8 @@ public final class InternalWorkbook {
     public int getSheetIndex(String name) {
         int retval = -1;
 
-        for (int k = 0; k < boundsheets.size(); k++) {
+        final int size = boundsheets.size();
+        for (int k = 0; k < size; k++) {
             String sheet = getSheetName(k);
 
             if (sheet.equalsIgnoreCase(name)) {
index 08504c3a6d4a8486fc7be91999d5dd30e328f8d4..e8be284f19c7bcb6a0cc91f1808966b4399ab73a 100644 (file)
@@ -806,12 +806,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
      */
     @Override
     public int getSheetIndex(org.apache.poi.ss.usermodel.Sheet sheet) {
-        for(int i=0; i<_sheets.size(); i++) {
-            if(_sheets.get(i) == sheet) {
-                return i;
-            }
-        }
-        return -1;
+        return _sheets.indexOf(sheet);
     }
 
     /**
index e14b8e0c5828f2bfda23d0fd39cbceda86842faf..f5e5f40fe8ccc548d68fdd2dbe3c8e9f69154b76 100644 (file)
@@ -182,7 +182,7 @@ public class WorkbookUtil {
             case Workbook.SHEET_STATE_HIDDEN: break;
             case Workbook.SHEET_STATE_VERY_HIDDEN: break;
             default: throw new IllegalArgumentException("Invalid sheet state : " + state + "\n" +
-                            "Sheet state must beone of the Workbook.SHEET_STATE_* constants");
+                            "Sheet state must be one of the Workbook.SHEET_STATE_* constants");
         }
     }