diff --git a/src/examples/jsp/HSSFExample.jsp b/src/examples/jsp/HSSFExample.jsp index b641846bd1..4dd0a4f4e5 100644 --- a/src/examples/jsp/HSSFExample.jsp +++ b/src/examples/jsp/HSSFExample.jsp @@ -32,7 +32,7 @@ Select an Excel file to read. <% String filename = request.getParameter("xls_filename"); - if (filename != null && !filename.equals("")) { + if (filename != null && !filename.isEmpty()) { %>
You chose the file <%= filename %>.

It's contents are: diff --git a/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java b/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java index 3177bc8779..d266b7475e 100644 --- a/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java +++ b/src/examples/src/org/apache/poi/ss/examples/html/ToHtml.java @@ -479,7 +479,7 @@ public class ToHtml { style.getDataFormatString()); CellFormatResult result = cf.apply(cell); content = result.text; - if (content.equals("")) { + if ("".equals(content)) { content = " "; } } diff --git a/src/java/org/apache/poi/hssf/usermodel/EscherGraphics.java b/src/java/org/apache/poi/hssf/usermodel/EscherGraphics.java index 5fce4c17de..ede62933ab 100644 --- a/src/java/org/apache/poi/hssf/usermodel/EscherGraphics.java +++ b/src/java/org/apache/poi/hssf/usermodel/EscherGraphics.java @@ -296,7 +296,7 @@ public class EscherGraphics extends Graphics @Override public void drawString(String str, int x, int y) { - if (str == null || str.equals("")) + if (str == null || str.isEmpty()) return; Font excelFont = font; diff --git a/src/java/org/apache/poi/ss/format/CellFormatPart.java b/src/java/org/apache/poi/ss/format/CellFormatPart.java index 02a4797835..951b5b8861 100644 --- a/src/java/org/apache/poi/ss/format/CellFormatPart.java +++ b/src/java/org/apache/poi/ss/format/CellFormatPart.java @@ -328,7 +328,7 @@ public class CellFormatPart { */ private CellFormatType formatType(String fdesc) { fdesc = fdesc.trim(); - if (fdesc.equals("") || fdesc.equalsIgnoreCase("General")) + if (fdesc.isEmpty() || fdesc.equalsIgnoreCase("General")) return CellFormatType.GENERAL; Matcher m = SPECIFICATION_PAT.matcher(fdesc); diff --git a/src/java/org/apache/poi/ss/formula/functions/DGet.java b/src/java/org/apache/poi/ss/formula/functions/DGet.java index 5cdc29251d..78b1b9235e 100644 --- a/src/java/org/apache/poi/ss/formula/functions/DGet.java +++ b/src/java/org/apache/poi/ss/formula/functions/DGet.java @@ -61,7 +61,7 @@ public final class DGet implements IDStarAlgorithm { return ErrorEval.VALUE_INVALID; } else try { - if(OperandResolver.coerceValueToString(OperandResolver.getSingleValue(result, 0, 0)).equals("")) { + if(OperandResolver.coerceValueToString(OperandResolver.getSingleValue(result, 0, 0)).isEmpty()) { return ErrorEval.VALUE_INVALID; } else { diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java index b6215a6c15..5c9a02e86e 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/OPCPackage.java @@ -847,7 +847,7 @@ public abstract class OPCPackage implements RelationshipSource, Closeable { throw new IllegalArgumentException("partName"); } - if (contentType == null || contentType.equals("")) { + if (contentType == null || contentType.isEmpty()) { throw new IllegalArgumentException("contentType"); } diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartCollection.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartCollection.java index ed0b9f7897..138a96258b 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartCollection.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartCollection.java @@ -56,7 +56,7 @@ public final class PackagePartCollection implements Serializable { PackagingURIHelper.FORWARD_SLASH_STRING); StringBuilder concatSeg = new StringBuilder(); for (String seg : segments) { - if (!seg.equals("")) + if (!seg.isEmpty()) concatSeg.append(PackagingURIHelper.FORWARD_SLASH_CHAR); concatSeg.append(seg); if (this.registerPartNameStr.contains(concatSeg.toString())) { diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartName.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartName.java index 37ee631776..099382d3be 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartName.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagePartName.java @@ -241,14 +241,14 @@ public final class PackagePartName implements Comparable { // Split the URI into several part and analyze each String[] segments = partUri.toASCIIString().split("/"); - if (segments.length <= 1 || !segments[0].equals("")) + if (segments.length <= 1 || !segments[0].isEmpty()) throw new InvalidFormatException( "A part name shall not have empty segments [M1.3]: " + partUri.getPath()); for (int i = 1; i < segments.length; ++i) { String seg = segments[i]; - if (seg == null || "".equals(seg)) { + if (seg == null || seg.isEmpty()) { throw new InvalidFormatException( "A part name shall not have empty segments [M1.3]: " + partUri.getPath()); diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java index 03b053132f..97d5c4d178 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/PackagingURIHelper.java @@ -35,6 +35,9 @@ import org.apache.poi.util.POILogger; * @version 0.1 */ public final class PackagingURIHelper { + // FIXME: this class implements a lot of path joining and splitting logic that + // is already implemented in java.nio.file.Path. + // This class should heavily leverage Java library code to reduce the number of lines of code that POI has to maintain and test private final static POILogger _logger = POILogFactory.getLogger(PackagingURIHelper.class); /** @@ -321,13 +324,13 @@ public final class PackagingURIHelper { // If we didn't have a good match or at least except a first empty element if ((segmentsTheSame == 0 || segmentsTheSame == 1) && - segmentsSource[0].equals("") && segmentsTarget[0].equals("")) { + segmentsSource[0].isEmpty() && segmentsTarget[0].isEmpty()) { for (int i = 0; i < segmentsSource.length - 2; i++) { retVal.append("../"); } for (int i = 0; i < segmentsTarget.length; i++) { - if (segmentsTarget[i].equals("")) - continue; + if (segmentsTarget[i].isEmpty()) + continue;i retVal.append(segmentsTarget[i]); if (i != segmentsTarget.length - 1) retVal.append("/"); diff --git a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java index b3d29d1724..e52da5bded 100644 --- a/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java +++ b/src/ooxml/java/org/apache/poi/openxml4j/opc/internal/PackagePropertiesPart.java @@ -566,7 +566,7 @@ public final class PackagePropertiesPart extends PackagePart implements * Convert a strig value into a Nullable */ private Nullable setStringValue(String s) { - if (s == null || s.equals("")) { + if (s == null || s.isEmpty()) { return new Nullable<>(); } return new Nullable<>(s); @@ -579,7 +579,7 @@ public final class PackagePropertiesPart extends PackagePart implements * Throws if the date format isnot valid. */ private Nullable setDateValue(String dateStr) throws InvalidFormatException { - if (dateStr == null || dateStr.equals("")) { + if (dateStr == null || dateStr.isEmpty()) { return new Nullable<>(); } diff --git a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java index abeac1ca79..cc51c44f19 100644 --- a/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java +++ b/src/ooxml/java/org/apache/poi/xssf/extractor/XSSFExportToXml.java @@ -382,7 +382,7 @@ public class XSSFExportToXml implements Comparator{ private boolean isNamespaceDeclared() { String schemaNamespace = getNamespace(); - return schemaNamespace!=null && !schemaNamespace.equals(""); + return schemaNamespace!=null && !schemaNamespace.isEmpty(); } private String getNamespace() { diff --git a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java index 61d8a1b7f8..338fb49473 100644 --- a/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java +++ b/src/ooxml/testcases/org/apache/poi/xssf/extractor/TestXSSFExportToXML.java @@ -76,7 +76,7 @@ public final class TestXSSFExportToXML { String xml = os.toString("UTF-8"); assertNotNull(xml); - assertFalse(xml.equals("")); + assertFalse(xml.isEmpty()); String docente = xml.split("")[1].split("")[0].trim(); String nome = xml.split("")[1].split("")[0].trim(); @@ -124,7 +124,7 @@ public final class TestXSSFExportToXML { String xml = os.toString("UTF-8"); assertNotNull(xml); - assertFalse(xml.equals("")); + assertFalse(xml.isEmpty()); String docente = xml.split("")[1].split("")[0].trim(); String nome = xml.split("")[1].split("")[0].trim(); @@ -256,7 +256,7 @@ public final class TestXSSFExportToXML { String xmlData = os.toString("UTF-8"); assertNotNull(xmlData); - assertFalse(xmlData.equals("")); + assertFalse(xmlData.isEmpty()); String a = xmlData.split("")[1].split("")[0].trim(); String b = a.split("")[1].split("")[0].trim(); @@ -299,7 +299,7 @@ public final class TestXSSFExportToXML { String xmlData = os.toString("UTF-8"); assertNotNull(xmlData); - assertFalse(xmlData.equals("")); + assertFalse(xmlData.isEmpty()); assertEquals("2012-01-13", xmlData.split("")[1].split("")[0].trim()); assertEquals("2012-02-16", xmlData.split("")[1].split("")[0].trim()); @@ -333,7 +333,7 @@ public final class TestXSSFExportToXML { String xmlData = os.toString("UTF-8"); assertNotNull(xmlData); - assertFalse(xmlData.equals("")); + assertFalse(xmlData.isEmpty()); String a = xmlData.split("")[1].split("")[0].trim(); String doubleValue = a.split("")[1].split("")[0].trim(); @@ -372,7 +372,7 @@ public final class TestXSSFExportToXML { String xmlData = os.toString("UTF-8"); assertNotNull(xmlData); - assertFalse(xmlData.equals("")); + assertFalse(xmlData.isEmpty()); String a = xmlData.split("")[1].split("")[0].trim(); String euro = a.split("")[1].split("")[0].trim(); @@ -397,7 +397,7 @@ public final class TestXSSFExportToXML { String xmlData = os.toString("UTF-8"); assertNotNull(xmlData); - assertTrue(!xmlData.equals("")); + assertTrue(!xmlData.isEmpty()); String a = xmlData.split("")[1].split("")[0].trim(); String a_b = a.split("")[1].split("")[0].trim(); @@ -472,7 +472,7 @@ public final class TestXSSFExportToXML { String xmlData = os.toString("UTF-8"); assertNotNull(xmlData); - assertFalse(xmlData.equals("")); + assertFalse(xmlData.isEmpty()); String a = xmlData.split("")[1].split("")[0].trim(); String a_b = a.split("")[1].split("")[0].trim(); @@ -569,7 +569,7 @@ public final class TestXSSFExportToXML { String xmlData = os.toString("UTF-8"); assertNotNull(xmlData); - assertFalse(xmlData.equals("")); + assertFalse(xmlData.isEmpty()); parseXML(xmlData); @@ -600,7 +600,7 @@ public final class TestXSSFExportToXML { String xmlData = os.toString("UTF-8"); assertNotNull(xmlData); - assertFalse(xmlData.equals("")); + assertFalse(xmlData.isEmpty()); parseXML(xmlData); @@ -631,7 +631,7 @@ public final class TestXSSFExportToXML { String xmlData = os.toString("UTF-8"); assertNotNull(xmlData); - assertFalse(xmlData.equals("")); + assertFalse(xmlData.isEmpty()); assertEquals("2014-12-31", xmlData.split("")[1].split("")[0].trim()); assertEquals("12.5", xmlData.split("")[1].split("")[0].trim()); diff --git a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java index 9f07cfb1c0..00bd9d3cf0 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java +++ b/src/testcases/org/apache/poi/ss/usermodel/BaseTestCell.java @@ -505,7 +505,7 @@ public abstract class BaseTestCell { assertEquals("abc", cellA1.getStringCellValue()); fe.evaluateInCell(cellA1); - assertFalse("Identified bug with writing back formula result of type string", cellA1.getStringCellValue().equals("")); + assertFalse("Identified bug with writing back formula result of type string", cellA1.getStringCellValue().isEmpty()); assertEquals("abc", cellA1.getStringCellValue()); wb.close();