From da595c23436b24e7412a45116297c5363dc282db Mon Sep 17 00:00:00 2001 From: Dominik Stadler Date: Sun, 17 Jul 2016 21:18:07 +0000 Subject: [PATCH] Fix some IntelliJ and Findbugs warnings: StringBuilder, foreach, append(), ... test-updates git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1753122 13f79535-47bb-0310-9956-ffa450edef68 --- .../poi/ddf/AbstractEscherOptRecord.java | 2 +- .../poi/ddf/DefaultEscherRecordFactory.java | 10 ++-- .../apache/poi/ddf/EscherComplexProperty.java | 13 ++--- .../org/apache/poi/ddf/EscherOptRecord.java | 12 ----- .../apache/poi/ddf/EscherPropertyFactory.java | 8 ++- src/java/org/apache/poi/ddf/EscherRecord.java | 19 +++---- .../org/apache/poi/dev/RecordGenerator.java | 13 +++-- .../apache/poi/hpsf/MutablePropertySet.java | 17 +++---- src/java/org/apache/poi/hpsf/PropertySet.java | 10 ++-- .../extractor/HPSFPropertiesExtractor.java | 37 ++++++++------ .../apache/poi/ss/formula/LazyAreaEval.java | 16 +++--- .../poi/ss/usermodel/DataFormatter.java | 49 ++++++++----------- src/java/org/apache/poi/util/HexRead.java | 2 +- .../poi/xwpf/extractor/XWPFWordExtractor.java | 6 +-- .../poi/ss/formula/functions/TestProper.java | 2 + .../hssf/extractor/TestExcelExtractor.java | 43 ++++------------ .../hssf/usermodel/TestHSSFDataFormatter.java | 10 ++-- .../apache/poi/poifs/dev/TestPOIFSDump.java | 2 +- .../poi/ss/usermodel/TestDataFormatter.java | 10 ++-- 19 files changed, 120 insertions(+), 161 deletions(-) diff --git a/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java b/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java index bf7f35d57..c8d2c95c8 100644 --- a/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java +++ b/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java @@ -207,7 +207,7 @@ public abstract class AbstractEscherOptRecord extends EscherRecord for ( EscherProperty property : properties ) { - stringBuilder.append( " " + property.toString() + nl ); + stringBuilder.append(" ").append(property.toString()).append(nl); } return stringBuilder.toString(); diff --git a/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java b/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java index 74407f293..4342708bf 100644 --- a/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java +++ b/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java @@ -85,12 +85,12 @@ public class DefaultEscherRecordFactory implements EscherRecordFactory { } Constructor recordConstructor = recordsMap.get(Short.valueOf(recordId)); - EscherRecord escherRecord = null; + final EscherRecord escherRecord; if (recordConstructor == null) { return new UnknownEscherRecord(); } try { - escherRecord = recordConstructor.newInstance(new Object[] {}); + escherRecord = recordConstructor.newInstance(); } catch (Exception e) { return new UnknownEscherRecord(); } @@ -111,9 +111,9 @@ public class DefaultEscherRecordFactory implements EscherRecordFactory { Map> result = new HashMap>(); final Class[] EMPTY_CLASS_ARRAY = new Class[0]; - for (int i = 0; i < recClasses.length; i++) { + for (Class recClass : recClasses) { @SuppressWarnings("unchecked") - Class recCls = (Class) recClasses[i]; + Class recCls = (Class) recClass; short sid; try { sid = recCls.getField("RECORD_ID").getShort(null); @@ -126,7 +126,7 @@ public class DefaultEscherRecordFactory implements EscherRecordFactory { } Constructor constructor; try { - constructor = recCls.getConstructor( EMPTY_CLASS_ARRAY ); + constructor = recCls.getConstructor(EMPTY_CLASS_ARRAY); } catch (NoSuchMethodException e) { throw new RuntimeException(e); } diff --git a/src/java/org/apache/poi/ddf/EscherComplexProperty.java b/src/java/org/apache/poi/ddf/EscherComplexProperty.java index 9c97ec044..9a84e10c1 100644 --- a/src/java/org/apache/poi/ddf/EscherComplexProperty.java +++ b/src/java/org/apache/poi/ddf/EscherComplexProperty.java @@ -112,9 +112,8 @@ public class EscherComplexProperty extends EscherProperty { EscherComplexProperty escherComplexProperty = (EscherComplexProperty) o; - if ( !Arrays.equals( _complexData, escherComplexProperty._complexData ) ) return false; + return Arrays.equals(_complexData, escherComplexProperty._complexData); - return true; } /** @@ -148,12 +147,10 @@ public class EscherComplexProperty extends EscherProperty { @Override public String toXml(String tab){ - StringBuilder builder = new StringBuilder(); - builder.append(tab).append("<").append(getClass().getSimpleName()).append(" id=\"0x").append(HexDump.toHex(getId())) - .append("\" name=\"").append(getName()).append("\" blipId=\"") - .append(isBlipId()).append("\">\n"); + return tab + "<" + getClass().getSimpleName() + " id=\"0x" + HexDump.toHex(getId()) + + "\" name=\"" + getName() + "\" blipId=\"" + + isBlipId() + "\">\n" + + tab + "\n"; //builder.append("\t").append(tab).append(dataStr); - builder.append(tab).append("\n"); - return builder.toString(); } } diff --git a/src/java/org/apache/poi/ddf/EscherOptRecord.java b/src/java/org/apache/poi/ddf/EscherOptRecord.java index 366b6cb85..cb6c7ad4c 100644 --- a/src/java/org/apache/poi/ddf/EscherOptRecord.java +++ b/src/java/org/apache/poi/ddf/EscherOptRecord.java @@ -16,7 +16,6 @@ ==================================================================== */ package org.apache.poi.ddf; -import org.apache.poi.util.HexDump; import org.apache.poi.util.Internal; /** @@ -72,15 +71,4 @@ public class EscherOptRecord extends AbstractEscherOptRecord super.setVersion( value ); } - - @Override - public String toXml(String tab) { - StringBuilder builder = new StringBuilder(); - builder.append(tab).append(formatXmlRecordHeader(getClass().getSimpleName(), HexDump.toHex(getRecordId()), HexDump.toHex(getVersion()), HexDump.toHex(getInstance()))); - for (EscherProperty property: getEscherProperties()){ - builder.append(property.toXml(tab+"\t")); - } - builder.append(tab).append("\n"); - return builder.toString(); - } } diff --git a/src/java/org/apache/poi/ddf/EscherPropertyFactory.java b/src/java/org/apache/poi/ddf/EscherPropertyFactory.java index 979655727..059e29ba9 100644 --- a/src/java/org/apache/poi/ddf/EscherPropertyFactory.java +++ b/src/java/org/apache/poi/ddf/EscherPropertyFactory.java @@ -18,7 +18,6 @@ package org.apache.poi.ddf; import java.util.ArrayList; -import java.util.Iterator; import java.util.List; import org.apache.poi.util.LittleEndian; @@ -72,16 +71,15 @@ public final class EscherPropertyFactory { } // Get complex data - for (Iterator iterator = results.iterator(); iterator.hasNext();) { - EscherProperty p = iterator.next(); + for (EscherProperty p : results) { if (p instanceof EscherComplexProperty) { if (p instanceof EscherArrayProperty) { pos += ((EscherArrayProperty)p).setArrayData(data, pos); } else { byte[] complexData = ((EscherComplexProperty)p).getComplexData(); - int leftover = data.length-pos; - if(leftover < complexData.length){ + int leftover = data.length - pos; + if (leftover < complexData.length) { throw new IllegalStateException("Could not read complex escher property, lenght was " + complexData.length + ", but had only " + leftover + " bytes left"); } diff --git a/src/java/org/apache/poi/ddf/EscherRecord.java b/src/java/org/apache/poi/ddf/EscherRecord.java index a0917b587..65926a8c1 100644 --- a/src/java/org/apache/poi/ddf/EscherRecord.java +++ b/src/java/org/apache/poi/ddf/EscherRecord.java @@ -84,8 +84,7 @@ public abstract class EscherRecord implements Cloneable { protected int readHeader( byte[] data, int offset ) { _options = LittleEndian.getShort( data, offset ); _recordId = LittleEndian.getShort( data, offset + 2 ); - int remainingBytes = LittleEndian.getInt( data, offset + 4 ); - return remainingBytes; + return LittleEndian.getInt( data, offset + 4 ); } /** @@ -312,19 +311,15 @@ public abstract class EscherRecord implements Cloneable { * @return xml representation of this record */ public String toXml(String tab){ - StringBuilder builder = new StringBuilder(); - builder.append(tab).append("<").append(getClass().getSimpleName()).append(">\n") - .append(tab).append("\t").append("0x").append(HexDump.toHex(_recordId)).append("\n") - .append(tab).append("\t").append("").append(_options).append("\n") - .append(tab).append("\n"); - return builder.toString(); + return tab + "<" + getClass().getSimpleName() + ">\n" + + tab + "\t" + "0x" + HexDump.toHex(_recordId) + "\n" + + tab + "\t" + "" + _options + "\n" + + tab + "\n"; } protected String formatXmlRecordHeader(String className, String recordId, String version, String instance){ - StringBuilder builder = new StringBuilder(); - builder.append("<").append(className).append(" recordId=\"0x").append(recordId).append("\" version=\"0x") - .append(version).append("\" instance=\"0x").append(instance).append("\" size=\"").append(getRecordSize()).append("\">\n"); - return builder.toString(); + return "<" + className + " recordId=\"0x" + recordId + "\" version=\"0x" + + version + "\" instance=\"0x" + instance + "\" size=\"" + getRecordSize() + "\">\n"; } public String toXml(){ diff --git a/src/java/org/apache/poi/dev/RecordGenerator.java b/src/java/org/apache/poi/dev/RecordGenerator.java index 2d3cdf3a9..585003c52 100644 --- a/src/java/org/apache/poi/dev/RecordGenerator.java +++ b/src/java/org/apache/poi/dev/RecordGenerator.java @@ -20,6 +20,7 @@ package org.apache.poi.dev; import java.io.File; import java.io.FileNotFoundException; +import java.io.IOException; import java.util.Locale; import java.util.Properties; @@ -92,8 +93,10 @@ public class RecordGenerator { // Generate record String destinationPath = destSrcPathDir + "/" + packageName; File destinationPathFile = new File(destinationPath); - if (destinationPathFile.mkdirs()) { - System.out.println("Created destination directory: " + destinationPath); + if(!destinationPathFile.mkdirs()) { + throw new IOException("Could not create directory " + destinationPathFile); + } else { + System.out.println("Created destination directory: " + destinationPath); } String destinationFilepath = destinationPath + "/" + recordName + suffix + ".java"; transform(file, new File(destinationFilepath), @@ -103,11 +106,13 @@ public class RecordGenerator { // Generate test (if not already generated) destinationPath = testSrcPathDir + "/" + packageName; destinationPathFile = new File(destinationPath); - if (destinationPathFile.mkdirs()) { + if(!destinationPathFile.mkdirs()) { + throw new IOException("Could not create directory " + destinationPathFile); + } else { System.out.println("Created destination directory: " + destinationPath); } destinationFilepath = destinationPath + "/Test" + recordName + suffix + ".java"; - if (new File(destinationFilepath).exists() == false) { + if (!new File(destinationFilepath).exists()) { String temp = (recordStyleDir + "/" + extendstg.toLowerCase(Locale.ROOT) + "_test.xsl"); transform(file, new File(destinationFilepath), new File(temp)); System.out.println("Generated test: " + destinationFilepath); diff --git a/src/java/org/apache/poi/hpsf/MutablePropertySet.java b/src/java/org/apache/poi/hpsf/MutablePropertySet.java index 748ec2a45..5c7d38658 100644 --- a/src/java/org/apache/poi/hpsf/MutablePropertySet.java +++ b/src/java/org/apache/poi/hpsf/MutablePropertySet.java @@ -97,7 +97,7 @@ public class MutablePropertySet extends PropertySet /** *

The length of the property set stream header.

*/ - private final int OFFSET_HEADER = + private final static int OFFSET_HEADER = BYTE_ORDER_ASSERTION.length + /* Byte order */ FORMAT_ASSERTION.length + /* Format */ LittleEndianConsts.INT_SIZE + /* OS version */ @@ -197,14 +197,13 @@ public class MutablePropertySet extends PropertySet { /* Write the number of sections in this property set stream. */ final int nrSections = sections.size(); - int length = 0; /* Write the property set's header. */ - length += TypeWriter.writeToStream(out, (short) getByteOrder()); - length += TypeWriter.writeToStream(out, (short) getFormat()); - length += TypeWriter.writeToStream(out, getOSVersion()); - length += TypeWriter.writeToStream(out, getClassID()); - length += TypeWriter.writeToStream(out, nrSections); + TypeWriter.writeToStream(out, (short) getByteOrder()); + TypeWriter.writeToStream(out, (short) getFormat()); + TypeWriter.writeToStream(out, getOSVersion()); + TypeWriter.writeToStream(out, getClassID()); + TypeWriter.writeToStream(out, nrSections); int offset = OFFSET_HEADER; /* Write the section list, i.e. the references to the sections. Each @@ -218,8 +217,8 @@ public class MutablePropertySet extends PropertySet final ClassID formatID = s.getFormatID(); if (formatID == null) throw new NoFormatIDException(); - length += TypeWriter.writeToStream(out, s.getFormatID()); - length += TypeWriter.writeUIntToStream(out, offset); + TypeWriter.writeToStream(out, s.getFormatID()); + TypeWriter.writeUIntToStream(out, offset); try { offset += s.getSize(); diff --git a/src/java/org/apache/poi/hpsf/PropertySet.java b/src/java/org/apache/poi/hpsf/PropertySet.java index b9ce01d62..9c9b1876a 100644 --- a/src/java/org/apache/poi/hpsf/PropertySet.java +++ b/src/java/org/apache/poi/hpsf/PropertySet.java @@ -24,6 +24,7 @@ import java.util.ArrayList; import java.util.List; import org.apache.poi.hpsf.wellknown.SectionIDMap; +import org.apache.poi.util.IOUtils; import org.apache.poi.util.LittleEndian; /** @@ -61,7 +62,7 @@ public class PropertySet *

The "byteOrder" field must equal this value.

*/ static final byte[] BYTE_ORDER_ASSERTION = - new byte[] {(byte) 0xFE, (byte) 0xFF}; + {(byte) 0xFE, (byte) 0xFF}; /** *

Specifies this {@link PropertySet}'s byte order. See the @@ -86,7 +87,7 @@ public class PropertySet *

The "format" field must equal this value.

*/ static final byte[] FORMAT_ASSERTION = - new byte[]{(byte) 0x00, (byte) 0x00}; + {(byte) 0x00, (byte) 0x00}; /** *

Specifies this {@link PropertySet}'s format. See the HPFS @@ -238,7 +239,7 @@ public class PropertySet { final int avail = stream.available(); final byte[] buffer = new byte[avail]; - stream.read(buffer, 0, buffer.length); + IOUtils.readFully(stream, buffer); init(buffer, 0, buffer.length); } else @@ -627,6 +628,7 @@ public class PropertySet * @return true if the objects are equal, false * if not */ + @Override public boolean equals(final Object o) { if (o == null || !(o instanceof PropertySet)) @@ -670,7 +672,7 @@ public class PropertySet */ public String toString() { - final StringBuffer b = new StringBuffer(); + final StringBuilder b = new StringBuilder(); final int sectionCount = getSectionCount(); b.append(getClass().getName()); b.append('['); diff --git a/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java b/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java index 0933ac25c..fc526ee61 100644 --- a/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java +++ b/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java @@ -19,7 +19,6 @@ package org.apache.poi.hpsf.extractor; import java.io.File; import java.io.IOException; -import java.util.Iterator; import org.apache.poi.POIDocument; import org.apache.poi.POIOLE2TextExtractor; @@ -59,7 +58,7 @@ public class HPSFPropertiesExtractor extends POIOLE2TextExtractor { } DocumentSummaryInformation dsi = document.getDocumentSummaryInformation(); - StringBuffer text = new StringBuffer(); + StringBuilder text = new StringBuilder(); // Normal properties text.append( getPropertiesText(dsi) ); @@ -67,11 +66,9 @@ public class HPSFPropertiesExtractor extends POIOLE2TextExtractor { // Now custom ones CustomProperties cps = dsi == null ? null : dsi.getCustomProperties(); if (cps != null) { - Iterator keys = cps.nameSet().iterator(); - while (keys.hasNext()) { - String key = keys.next(); - String val = HelperPropertySet.getPropertyValueText( cps.get(key) ); - text.append(key + " = " + val + "\n"); + for (String key : cps.nameSet()) { + String val = HelperPropertySet.getPropertyValueText(cps.get(key)); + text.append(key).append(" = ").append(val).append("\n"); } } @@ -95,19 +92,19 @@ public class HPSFPropertiesExtractor extends POIOLE2TextExtractor { return ""; } - StringBuffer text = new StringBuffer(); + StringBuilder text = new StringBuilder(); PropertyIDMap idMap = ps.getPropertySetIDMap(); Property[] props = ps.getProperties(); - for (int i=0; i -1) { - StringBuffer sb = new StringBuffer(); - sb.append(symbol.substring(0, symbol.indexOf('$'))); - sb.append('\\'); - sb.append(symbol.substring(symbol.indexOf('$'), symbol.length())); - symbol = sb.toString(); + symbol = symbol.substring(0, symbol.indexOf('$')) + + '\\' + + symbol.substring(symbol.indexOf('$'), symbol.length()); } formatStr = m.replaceAll(symbol); m = localePatternGroup.matcher(formatStr); @@ -426,16 +423,16 @@ public class DataFormatter implements Observer { return createDateFormat(formatStr, cellValue); } // Excel supports fractions in format strings, which Java doesn't - if (formatStr.indexOf("#/") >= 0 || formatStr.indexOf("?/") >= 0) { + if (formatStr.contains("#/") || formatStr.contains("?/")) { String[] chunks = formatStr.split(";"); - for (int i = 0; i < chunks.length; i++){ - String chunk = chunks[i].replaceAll("\\?", "#"); + for (String chunk1 : chunks) { + String chunk = chunk1.replaceAll("\\?", "#"); Matcher matcher = fractionStripper.matcher(chunk); chunk = matcher.replaceAll(" "); chunk = chunk.replaceAll(" +", " "); Matcher fractionMatcher = fractionPattern.matcher(chunk); //take the first match - if (fractionMatcher.find()){ + if (fractionMatcher.find()) { String wholePart = (fractionMatcher.group(1) == null) ? "" : defaultFractionWholePartFormat; return new FractionFormat(wholePart, fractionMatcher.group(3)); } @@ -498,7 +495,7 @@ public class DataFormatter implements Observer { Excel displays the month instead of minutes." */ - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); char[] chars = formatStr.toCharArray(); boolean mIsMonth = true; List ms = new ArrayList(); @@ -565,7 +562,7 @@ public class DataFormatter implements Observer { // if 'M' precedes 's' it should be minutes ('m') for (int index : ms) { if (sb.charAt(index) == 'M') { - sb.replace(index, index+1, "m"); + sb.replace(index, index + 1, "m"); } } mIsMonth = true; @@ -602,7 +599,7 @@ public class DataFormatter implements Observer { } private String cleanFormatForNumber(String formatStr) { - StringBuffer sb = new StringBuffer(formatStr); + StringBuilder sb = new StringBuilder(formatStr); if (emulateCSV) { // Requested spacers with "_" are replaced by a single space. @@ -927,9 +924,7 @@ public class DataFormatter implements Observer { * @see java.text.Format#format */ public void setDefaultNumberFormat(Format format) { - Iterator> itr = formats.entrySet().iterator(); - while(itr.hasNext()) { - Map.Entry entry = itr.next(); + for (Map.Entry entry : formats.entrySet()) { if (entry.getValue() == generalNumberFormat) { entry.setValue(format); } @@ -1054,11 +1049,9 @@ public class DataFormatter implements Observer { /** Format a number as an SSN */ public static String format(Number num) { String result = df.format(num); - StringBuffer sb = new StringBuffer(); - sb.append(result.substring(0, 3)).append('-'); - sb.append(result.substring(3, 5)).append('-'); - sb.append(result.substring(5, 9)); - return sb.toString(); + return result.substring(0, 3) + '-' + + result.substring(3, 5) + '-' + + result.substring(5, 9); } @Override @@ -1088,10 +1081,8 @@ public class DataFormatter implements Observer { /** Format a number as Zip + 4 */ public static String format(Number num) { String result = df.format(num); - StringBuffer sb = new StringBuffer(); - sb.append(result.substring(0, 5)).append('-'); - sb.append(result.substring(5, 9)); - return sb.toString(); + return result.substring(0, 5) + '-' + + result.substring(5, 9); } @Override @@ -1121,7 +1112,7 @@ public class DataFormatter implements Observer { /** Format a number as a phone number */ public static String format(Number num) { String result = df.format(num); - StringBuffer sb = new StringBuffer(); + StringBuilder sb = new StringBuilder(); String seg1, seg2, seg3; int len = result.length(); if (len <= 4) { @@ -1132,10 +1123,10 @@ public class DataFormatter implements Observer { seg2 = result.substring(Math.max(0, len - 7), len - 4); seg1 = result.substring(Math.max(0, len - 10), Math.max(0, len - 7)); - if(seg1 != null && seg1.trim().length() > 0) { + if(seg1.trim().length() > 0) { sb.append('(').append(seg1).append(") "); } - if(seg2 != null && seg2.trim().length() > 0) { + if(seg2.trim().length() > 0) { sb.append(seg2).append('-'); } sb.append(seg3); diff --git a/src/java/org/apache/poi/util/HexRead.java b/src/java/org/apache/poi/util/HexRead.java index 165ad0313..4d9ac9752 100644 --- a/src/java/org/apache/poi/util/HexRead.java +++ b/src/java/org/apache/poi/util/HexRead.java @@ -139,7 +139,7 @@ public class HexRead } } } - Byte[] polished = bytes.toArray( new Byte[0] ); + Byte[] polished = bytes.toArray(new Byte[bytes.size()]); byte[] rval = new byte[polished.length]; for ( int j = 0; j < polished.length; j++ ) { diff --git a/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java b/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java index 3b7fb443b..712e04b73 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java +++ b/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java @@ -45,7 +45,7 @@ import org.openxmlformats.schemas.wordprocessingml.x2006.main.CTSectPr; * Helper class to extract text from an OOXML Word file */ public class XWPFWordExtractor extends POIXMLTextExtractor { - public static final XWPFRelation[] SUPPORTED_TYPES = new XWPFRelation[]{ + public static final XWPFRelation[] SUPPORTED_TYPES = { XWPFRelation.DOCUMENT, XWPFRelation.TEMPLATE, XWPFRelation.MACRO_DOCUMENT, XWPFRelation.MACRO_TEMPLATE_DOCUMENT @@ -134,7 +134,7 @@ public class XWPFWordExtractor extends POIXMLTextExtractor { if (run instanceof XWPFHyperlinkRun && fetchHyperlinks) { XWPFHyperlink link = ((XWPFHyperlinkRun) run).getHyperlink(document); if (link != null) - text.append(" <" + link.getURL() + ">"); + text.append(" <").append(link.getURL()).append(">"); } } @@ -148,7 +148,7 @@ public class XWPFWordExtractor extends POIXMLTextExtractor { // Do endnotes and footnotes String footnameText = paragraph.getFootnoteText(); if (footnameText != null && footnameText.length() > 0) { - text.append(footnameText + '\n'); + text.append(footnameText).append('\n'); } if (ctSectPr != null) { diff --git a/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java b/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java index dd3eeb599..d86079eca 100644 --- a/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java +++ b/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java @@ -35,6 +35,7 @@ import junit.framework.TestCase; import org.junit.Test; import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; public final class TestProper { private Cell cell11; @@ -74,6 +75,7 @@ public final class TestProper { final String scharfes = "\u00df"; //German lowercase eszett, scharfes s, sharp s confirm("PROPER(\"stra"+scharfes+"e\")", "Stra"+scharfes+"e"); + assertTrue(Character.isLetter(scharfes.charAt(0))); // CURRENTLY FAILS: result: "SSUnd"+scharfes // LibreOffice 5.0.3.2 behavior: "Sund"+scharfes diff --git a/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java b/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java index 7f980e29c..6156cb1b5 100644 --- a/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java +++ b/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java @@ -265,37 +265,14 @@ public final class TestExcelExtractor { assertTrue(text.startsWith( "Dates, all 24th November 2006\n" )); - assertTrue( - text.indexOf( - "yyyy/mm/dd\t2006/11/24\n" - ) > -1 - ); - assertTrue( - text.indexOf( - "yyyy-mm-dd\t2006-11-24\n" - ) > -1 - ); - assertTrue( - text.indexOf( - "dd-mm-yy\t24-11-06\n" - ) > -1 - ); + assertTrue(text.contains("yyyy/mm/dd\t2006/11/24\n")); + assertTrue(text.contains("yyyy-mm-dd\t2006-11-24\n")); + assertTrue(text.contains("dd-mm-yy\t24-11-06\n")); assertTrue("Had: " + text + ", but should contain 'nn.nn\\t10.52\\n'", - text.indexOf( - "nn.nn\t10.52\n" - ) > -1 - ); - assertTrue( - text.indexOf( - "nn.nnn\t10.520\n" - ) > -1 - ); - assertTrue( - text.indexOf( - "\u00a3nn.nn\t\u00a310.52\n" - ) > -1 - ); + text.contains("nn.nn\t10.52\n")); + assertTrue(text.contains("nn.nnn\t10.520\n")); + assertTrue(text.contains("\u00a3nn.nn\t\u00a310.52\n")); extractor.close(); } finally { LocaleUtil.setUserLocale(userLocale); @@ -387,11 +364,11 @@ public final class TestExcelExtractor { "45538_classic_Footer.xls", "45538_form_Footer.xls", "45538_classic_Header.xls", "45538_form_Header.xls" }; - for(int i=0; i=0); - assertTrue("Unable to find expected word in text\n" + text, text.indexOf("test phrase") >= 0); + assertTrue("Unable to find expected word in text\n" + text, text.contains("testdoc")); + assertTrue("Unable to find expected word in text\n" + text, text.contains("test phrase")); extractor.close(); } } diff --git a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java index 50d320a96..35c307ba4 100644 --- a/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java +++ b/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java @@ -246,18 +246,18 @@ public final class TestHSSFDataFormatter { String fmt = cell.getCellStyle().getDataFormatString(); //assert the correct month form, as in the original Excel format - String monthPtrn = fmt.indexOf("mmmm") != -1 ? "MMMM" : "MMM"; + String monthPtrn = fmt.contains("mmmm") ? "MMMM" : "MMM"; // this line is intended to compute how "July" would look like in the current locale SimpleDateFormat sdf = new SimpleDateFormat(monthPtrn, LocaleUtil.getUserLocale()); sdf.setTimeZone(LocaleUtil.getUserTimeZone()); Calendar calDef = LocaleUtil.getLocaleCalendar(2010, 6, 15, 0, 0, 0); String jul = sdf.format(calDef.getTime()); // special case for MMMMM = 1st letter of month name - if(fmt.indexOf("mmmmm") > -1) { + if(fmt.contains("mmmmm")) { jul = jul.substring(0,1); } // check we found july properly - assertTrue("Format came out incorrect - " + fmt, fmtval.indexOf(jul) > -1); + assertTrue("Format came out incorrect - " + fmt, fmtval.contains(jul)); } row = wb.getSheetAt(0).getRow(1); @@ -275,7 +275,7 @@ public final class TestHSSFDataFormatter { // check we found the time properly assertTrue("Format came out incorrect - " + fmt + " - found " + fmtval + - ", but expected to find '11:23'", fmtval.indexOf("11:23") > -1); + ", but expected to find '11:23'", fmtval.contains("11:23")); } // test number formats @@ -451,7 +451,7 @@ public final class TestHSSFDataFormatter { assertEquals("\u00a310.52", f.formatCellValue(sheet.getRow(12).getCell(1))); } - private static void log(String msg) { + private static void log(@SuppressWarnings("UnusedParameters") String msg) { // if (false) { // successful tests should be silent // System.out.println(msg); // } diff --git a/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java b/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java index 4c8f8d13e..00dfc7eae 100644 --- a/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java +++ b/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java @@ -39,7 +39,7 @@ public class TestPOIFSDump { private static final String INVALID_FILE = HSSFTestDataSamples.getSampleFile("48936-strings.txt").getAbsolutePath(); private static final String INVALID_XLSX_FILE = HSSFTestDataSamples.getSampleFile("47668.xlsx").getAbsolutePath(); - private static final String[] DUMP_OPTIONS = new String[] { + private static final String[] DUMP_OPTIONS = { "-dumprops", "-dump-props", "-dump-properties", diff --git a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java index f5e79c8c9..649bddf9b 100644 --- a/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java +++ b/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java @@ -140,7 +140,7 @@ public class TestDataFormatter { public void testColours() { DataFormatter dfUS = new DataFormatter(Locale.US); - String[] formats = new String[] { + String[] formats = { "##.##", "[WHITE]##.##", "[BLACK]##.##;[RED]-##.##", @@ -169,7 +169,7 @@ public class TestDataFormatter { DataFormatter dfUS = new DataFormatter(Locale.US); // Without currency symbols - String[] formats = new String[] { "#,##0.00;[Blue](#,##0.00)" }; + String[] formats = { "#,##0.00;[Blue](#,##0.00)" }; for (String format : formats) { assertEquals( "Wrong format for: " + format, @@ -304,7 +304,7 @@ public class TestDataFormatter { assertEquals("321 1/3", dfUS.formatRawCellContents(321.321, -1, "# ?/? ?/?")); assertEquals("321 1/3", dfUS.formatRawCellContents(321.321, -1, "# ?/? #/# #/#")); - // Where +ve has a fraction, but -ve doesnt, we currently show both + // Where +ve has a fraction, but -ve doesn't, we currently show both assertEquals("123 1/3", dfUS.formatRawCellContents( 123.321, -1, "0 ?/?;0")); //assertEquals("123", dfUS.formatRawCellContents(-123.321, -1, "0 ?/?;0")); @@ -567,12 +567,12 @@ public class TestDataFormatter { assertEquals(" 0.10 ", dfUS.formatRawCellContents( 0.1, -1, "_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-")); assertEquals("- 0.10 ", dfUS.formatRawCellContents(-0.1, -1, "_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-")); - // TODO Fix this, we are randomly adding a 0 at the end that souldn't be there + // TODO Fix this, we are randomly adding a 0 at the end that shouldn't be there //assertEquals(" - ", dfUS.formatRawCellContents(0.0, -1, "_-* #,##0.00_-;-* #,##0.00_-;_-* \"-\"??_-;_-@_-")); assertEquals(" $ 1.10 ", dfUS.formatRawCellContents( 1.1, -1, "_-$* #,##0.00_-;-$* #,##0.00_-;_-$* \"-\"??_-;_-@_-")); assertEquals("-$ 1.10 ", dfUS.formatRawCellContents(-1.1, -1, "_-$* #,##0.00_-;-$* #,##0.00_-;_-$* \"-\"??_-;_-@_-")); - // TODO Fix this, we are randomly adding a 0 at the end that souldn't be there + // TODO Fix this, we are randomly adding a 0 at the end that shouldn't be there //assertEquals(" $ - ", dfUS.formatRawCellContents( 0.0, -1, "_-$* #,##0.00_-;-$* #,##0.00_-;_-$* \"-\"??_-;_-@_-")); }