diff --git a/poi-ooxml/src/main/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java b/poi-ooxml/src/main/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java index 124a2818ed..93d7016580 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java +++ b/poi-ooxml/src/main/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java @@ -187,11 +187,11 @@ public final class POIXMLExtractorFactory implements ExtractorProvider { core = pkg.getRelationshipsByType(CORE_DOCUMENT_REL); // If nothing was found, try some of the other OOXML-based core types - if (core.size() == 0) { + if (core.isEmpty()) { // Could it be an OOXML-Strict one? core = pkg.getRelationshipsByType(STRICT_DOCUMENT_REL); } - if (core.size() == 0) { + if (core.isEmpty()) { // Could it be a visio one? core = pkg.getRelationshipsByType(VISIO_DOCUMENT_REL); if (core.size() == 1) { diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java index a96b8d59d0..b19b3c1d08 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java +++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java @@ -1351,7 +1351,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { @Override public boolean hasRelationships() { - return (relationships.size() > 0); + return !relationships.isEmpty(); } @Override @@ -1644,7 +1644,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { public boolean isStrictOoxmlFormat() { PackageRelationshipCollection coreDocRelationships = getRelationshipsByType( PackageRelationshipTypes.STRICT_CORE_DOCUMENT); - return coreDocRelationships.size() > 0; + return !coreDocRelationships.isEmpty(); } /** diff --git a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackagePart.java b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackagePart.java index 2aaf907d5e..70f5654ddd 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackagePart.java +++ b/poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackagePart.java @@ -442,8 +442,7 @@ public abstract class PackagePart implements RelationshipSource, Comparable 0)); + return (!this._isRelationshipPart && (_relationships != null && !_relationships.isEmpty())); } /** diff --git a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java index 79ffdb1c44..f6bf6b563b 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java @@ -195,7 +195,7 @@ public class XSLFSlideShow extends POIXMLDocument { throw new IllegalStateException(e); } - if(notes.size() == 0) { + if(notes.isEmpty()) { // No notes for this slide return null; } @@ -239,7 +239,7 @@ public class XSLFSlideShow extends POIXMLDocument { throw new IllegalStateException(e); } - if(commentRels.size() == 0) { + if(commentRels.isEmpty()) { // No comments for this slide return null; } diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java index deebf72836..d9a24bb855 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java @@ -158,7 +158,7 @@ public class XSSFBReader extends XSSFReader { try { PackageRelationshipCollection commentsList = sheetPkg.getRelationshipsByType(XSSFRelation.SHEET_COMMENTS.getRelation()); - if (commentsList.size() > 0) { + if (!commentsList.isEmpty()) { PackageRelationship comments = commentsList.getRelationship(0); if (comments == null || comments.getTargetURI() == null) { return null; diff --git a/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java b/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java index 4f668aa0f7..220f5b89c4 100644 --- a/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java +++ b/poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java @@ -373,7 +373,7 @@ public class XSSFReader { try { PackageRelationshipCollection commentsList = sheetPkg.getRelationshipsByType(XSSFRelation.SHEET_COMMENTS.getRelation()); - if (commentsList.size() > 0) { + if (!commentsList.isEmpty()) { PackageRelationship comments = commentsList.getRelationship(0); PackagePartName commentsName = PackagingURIHelper.createPartName(comments.getTargetURI()); PackagePart commentsPart = sheetPkg.getPackage().getPart(commentsName); @@ -401,7 +401,8 @@ public class XSSFReader { // Do we have a shapes relationship? (Only ever one if so) try { PackageRelationshipCollection drawingsList = sheetPkg.getRelationshipsByType(XSSFRelation.DRAWINGS.getRelation()); - for (int i = 0; i < drawingsList.size(); i++) { + int drawingsSize = drawingsList.size(); + for (int i = 0; i < drawingsSize; i++) { PackageRelationship drawings = drawingsList.getRelationship(i); PackagePartName drawingsName = PackagingURIHelper.createPartName(drawings.getTargetURI()); PackagePart drawingsPart = sheetPkg.getPackage().getPart(drawingsName); diff --git a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java index 37b2885b5f..81c78f41dc 100644 --- a/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java +++ b/poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java @@ -17,6 +17,7 @@ package org.apache.poi.openxml4j.opc; +import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertNotEquals; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -50,7 +51,7 @@ public final class TestPackageThumbnail { // Open the newly created file to check core properties saved values. try (OPCPackage p2 = OPCPackage.open(outputFile.getAbsolutePath(), PackageAccess.READ)) { - assertNotEquals(0, p2.getRelationshipsByType(PackageRelationshipTypes.THUMBNAIL).size(), + assertFalse(p2.getRelationshipsByType(PackageRelationshipTypes.THUMBNAIL).isEmpty(), "Thumbnail not added to the package !"); p2.revert(); }