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
This commit is contained in:
Javen O'Neal 2016-10-19 08:38:19 +00:00
parent 9cad5aff09
commit 425e04b4a4

View File

@ -186,7 +186,7 @@ public class XSSFReader {
/** /**
* Maps relId and the corresponding PackagePart * Maps relId and the corresponding PackagePart
*/ */
private Map<String, PackagePart> sheetMap; private final Map<String, PackagePart> sheetMap;
/** /**
* Current CTSheet bean * 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, * 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 * i.e. as they are stored in the underlying package
*/ */
private Iterator<CTSheet> sheetIterator; private final Iterator<CTSheet> sheetIterator;
/** /**
* Construct a new SheetIterator * Construct a new SheetIterator
@ -213,11 +213,14 @@ public class XSSFReader {
try { try {
//step 1. Map sheet's relationship Id and the corresponding PackagePart //step 1. Map sheet's relationship Id and the corresponding PackagePart
sheetMap = new HashMap<String, PackagePart>(); sheetMap = new HashMap<String, PackagePart>();
OPCPackage pkg = wb.getPackage();
String REL_WORKSHEET = XSSFRelation.WORKSHEET.getRelation();
String REL_CHARTSHEET = XSSFRelation.CHARTSHEET.getRelation();
for(PackageRelationship rel : wb.getRelationships()){ for(PackageRelationship rel : wb.getRelationships()){
if(rel.getRelationshipType().equals(XSSFRelation.WORKSHEET.getRelation()) || String relType = rel.getRelationshipType();
rel.getRelationshipType().equals(XSSFRelation.CHARTSHEET.getRelation())){ if (relType.equals(REL_WORKSHEET) || relType.equals(REL_CHARTSHEET)) {
PackagePartName relName = PackagingURIHelper.createPartName(rel.getTargetURI()); 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 //step 2. Read array of CTSheet elements, wrap it in a ArayList and construct an iterator
@ -236,6 +239,7 @@ public class XSSFReader {
* *
* @return <tt>true</tt> if the iterator has more elements. * @return <tt>true</tt> if the iterator has more elements.
*/ */
@Override
public boolean hasNext() { public boolean hasNext() {
return sheetIterator.hasNext(); return sheetIterator.hasNext();
} }
@ -245,6 +249,7 @@ public class XSSFReader {
* *
* @return input stream of the next sheet in the iteration * @return input stream of the next sheet in the iteration
*/ */
@Override
public InputStream next() { public InputStream next() {
ctSheet = sheetIterator.next(); ctSheet = sheetIterator.next();
@ -328,6 +333,7 @@ public class XSSFReader {
/** /**
* We're read only, so remove isn't supported * We're read only, so remove isn't supported
*/ */
@Override
public void remove() { public void remove() {
throw new IllegalStateException("Not supported"); throw new IllegalStateException("Not supported");
} }