methods that return lists should return unmodifiable lists; use foreach sheet iterator when sheet index is not needed

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1747843 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Javen O'Neal 2016-06-11 03:05:31 +00:00
parent ed3364b6d2
commit 8673812492

View File

@ -38,6 +38,7 @@ import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import java.util.Collections;
import org.apache.commons.codec.digest.DigestUtils; import org.apache.commons.codec.digest.DigestUtils;
import org.apache.poi.EncryptedDocumentException; import org.apache.poi.EncryptedDocumentException;
@ -1475,7 +1476,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
} }
} }
return nameList; return Collections.unmodifiableList(nameList);
} }
@Override @Override
@ -1721,8 +1722,8 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
void initDrawings(){ void initDrawings(){
DrawingManager2 mgr = workbook.findDrawingGroup(); DrawingManager2 mgr = workbook.findDrawingGroup();
if(mgr != null) { if(mgr != null) {
for(int i=0; i < getNumberOfSheets(); i++) { for(HSSFSheet sh : _sheets) {
getSheetAt(i).getDrawingPatriarch(); sh.getDrawingPatriarch();
} }
} else { } else {
workbook.createDrawingGroup(); workbook.createDrawingGroup();
@ -1840,7 +1841,7 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
searchForPictures(escherRecords, pictures); searchForPictures(escherRecords, pictures);
} }
} }
return pictures; return Collections.unmodifiableList(pictures);
} }
/** /**
@ -1976,11 +1977,11 @@ public final class HSSFWorkbook extends POIDocument implements org.apache.poi.ss
public List<HSSFObjectData> getAllEmbeddedObjects() public List<HSSFObjectData> getAllEmbeddedObjects()
{ {
List<HSSFObjectData> objects = new ArrayList<HSSFObjectData>(); List<HSSFObjectData> objects = new ArrayList<HSSFObjectData>();
for (int i = 0; i < getNumberOfSheets(); i++) for (HSSFSheet sheet : _sheets)
{ {
getAllEmbeddedObjects(getSheetAt(i), objects); getAllEmbeddedObjects(sheet, objects);
} }
return objects; return Collections.unmodifiableList(objects);
} }
/** /**