add isEmpty() method

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1896524 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2021-12-30 06:18:09 +00:00
parent 6d93ac6172
commit 6aa1e58bdf
7 changed files with 13 additions and 12 deletions

View 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) {

View 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();
}
/**

View 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()));
}
/**

View 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;
}

View 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;

View 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);

View 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();
}