From: Javen O'Neal Date: Wed, 19 Oct 2016 08:38:19 +0000 (+0000) Subject: add @Override decorators to SheetIterator, move code outside of for-loop X-Git-Tag: REL_3_16_BETA1~79 X-Git-Url: https://source.dussan.org/?a=commitdiff_plain;h=90eb45410ab258e9029e7448492e402cbca23de5;p=poi.git add @Override decorators to SheetIterator, move code outside of for-loop git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1765556 13f79535-47bb-0310-9956-ffa450edef68 --- diff --git a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java index 2060a870a8..8d50bc62cd 100644 --- a/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java +++ b/src/ooxml/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java @@ -186,7 +186,7 @@ public class XSSFReader { /** * Maps relId and the corresponding PackagePart */ - private Map sheetMap; + private final Map sheetMap; /** * Current CTSheet bean @@ -198,7 +198,7 @@ public class XSSFReader { * We can't rely on the Ooxml4J's relationship iterator because it returns objects in physical order, * i.e. as they are stored in the underlying package */ - private Iterator sheetIterator; + private final Iterator sheetIterator; /** * Construct a new SheetIterator @@ -213,11 +213,14 @@ public class XSSFReader { try { //step 1. Map sheet's relationship Id and the corresponding PackagePart sheetMap = new HashMap(); + OPCPackage pkg = wb.getPackage(); + String REL_WORKSHEET = XSSFRelation.WORKSHEET.getRelation(); + String REL_CHARTSHEET = XSSFRelation.CHARTSHEET.getRelation(); for(PackageRelationship rel : wb.getRelationships()){ - if(rel.getRelationshipType().equals(XSSFRelation.WORKSHEET.getRelation()) || - rel.getRelationshipType().equals(XSSFRelation.CHARTSHEET.getRelation())){ + String relType = rel.getRelationshipType(); + if (relType.equals(REL_WORKSHEET) || relType.equals(REL_CHARTSHEET)) { PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI()); - sheetMap.put(rel.getId(), wb.getPackage().getPart(relName)); + sheetMap.put(rel.getId(), pkg.getPart(relName)); } } //step 2. Read array of CTSheet elements, wrap it in a ArayList and construct an iterator @@ -236,6 +239,7 @@ public class XSSFReader { * * @return true if the iterator has more elements. */ + @Override public boolean hasNext() { return sheetIterator.hasNext(); } @@ -245,6 +249,7 @@ public class XSSFReader { * * @return input stream of the next sheet in the iteration */ + @Override public InputStream next() { ctSheet = sheetIterator.next(); @@ -328,6 +333,7 @@ public class XSSFReader { /** * We're read only, so remove isn't supported */ + @Override public void remove() { throw new IllegalStateException("Not supported"); }