]> source.dussan.org Git - poi.git/commitdiff
add isEmpty() method
authorPJ Fanning <fanningpj@apache.org>
Thu, 30 Dec 2021 06:18:09 +0000 (06:18 +0000)
committerPJ Fanning <fanningpj@apache.org>
Thu, 30 Dec 2021 06:18:09 +0000 (06:18 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896524 13f79535-47bb-0310-9956-ffa450edef68

poi-ooxml/src/main/java/org/apache/poi/ooxml/extractor/POIXMLExtractorFactory.java
poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/OPCPackage.java
poi-ooxml/src/main/java/org/apache/poi/openxml4j/opc/PackagePart.java
poi-ooxml/src/main/java/org/apache/poi/xslf/usermodel/XSLFSlideShow.java
poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFBReader.java
poi-ooxml/src/main/java/org/apache/poi/xssf/eventusermodel/XSSFReader.java
poi-ooxml/src/test/java/org/apache/poi/openxml4j/opc/TestPackageThumbnail.java

index 124a2818ed209923643cc46d4c6196b57c99b813..93d7016580be43f8f5988416fc3f37cdef1d5191 100644 (file)
@@ -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) {
index a96b8d59d0a7ecf16cac0ba83340c7ea52631f74..b19b3c1d089ef532586d05d2d06fcd3a3b0c5afd 100644 (file)
@@ -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();
     }
 
     /**
index 2aaf907d5eb85868dee718a714bed94aca275f64..70f5654ddd946322f19027ae141b7434c9c3d001 100644 (file)
@@ -442,8 +442,7 @@ public abstract class PackagePart implements RelationshipSource, Comparable<Pack
      */
     @Override
     public boolean hasRelationships() {
-        return (!this._isRelationshipPart && (_relationships != null && _relationships
-                .size() > 0));
+        return (!this._isRelationshipPart && (_relationships != null && !_relationships.isEmpty()));
     }
 
     /**
index 79ffdb1c44ce108b094a6a150eb28c7455e46886..f6bf6b563b90e5b5c59bf9f61e98623fa633ab9d 100644 (file)
@@ -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;
         }
index deebf72836cce0b13439b1a3528b459f0d96a1a2..d9a24bb855dd1d648cd5d14ccf2ed42589d577ea 100644 (file)
@@ -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;
index 4f668aa0f7bd44dd7e3a34d197f0817fc01b25e4..220f5b89c48aedd34252367cbdaa7be317cf38da 100644 (file)
@@ -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);
index 37b2885b5fd4bb6c92ad581b422420d263d81d12..81c78f41dc0927b97ef054c33e9d8b2b98d1b32d 100644 (file)
@@ -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();
             }