pull out loop invariants, use List.indexOf to look up sheet index

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1779560 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2017-01-20 04:38:18 +00:00
parent 15be6fb336
commit 647f0a90a2
3 changed files with 4 additions and 8 deletions

View 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)) {

View 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);
}
/**

View 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");
}
}