You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@poi.apache.org by ce...@apache.org on 2016/07/17 21:18:07 UTC

svn commit: r1753122 - in /poi/trunk/src: java/org/apache/poi/ddf/ java/org/apache/poi/dev/ java/org/apache/poi/hpsf/ java/org/apache/poi/hpsf/extractor/ java/org/apache/poi/ss/formula/ java/org/apache/poi/ss/usermodel/ java/org/apache/poi/util/ ooxml/...

Author: centic
Date: Sun Jul 17 21:18:07 2016
New Revision: 1753122

URL: http://svn.apache.org/viewvc?rev=1753122&view=rev
Log:
Fix some IntelliJ and Findbugs warnings: StringBuilder, foreach, append(), ...
test-updates

Modified:
    poi/trunk/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java
    poi/trunk/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java
    poi/trunk/src/java/org/apache/poi/ddf/EscherComplexProperty.java
    poi/trunk/src/java/org/apache/poi/ddf/EscherOptRecord.java
    poi/trunk/src/java/org/apache/poi/ddf/EscherPropertyFactory.java
    poi/trunk/src/java/org/apache/poi/ddf/EscherRecord.java
    poi/trunk/src/java/org/apache/poi/dev/RecordGenerator.java
    poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java
    poi/trunk/src/java/org/apache/poi/hpsf/PropertySet.java
    poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
    poi/trunk/src/java/org/apache/poi/ss/formula/LazyAreaEval.java
    poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
    poi/trunk/src/java/org/apache/poi/util/HexRead.java
    poi/trunk/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java
    poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java
    poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java
    poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java
    poi/trunk/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java
    poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java

Modified: poi/trunk/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java Sun Jul 17 21:18:07 2016
@@ -207,7 +207,7 @@ public abstract class AbstractEscherOptR
 
         for ( EscherProperty property : properties )
         {
-            stringBuilder.append( "    " + property.toString() + nl );
+            stringBuilder.append("    ").append(property.toString()).append(nl);
         }
 
         return stringBuilder.toString();

Modified: poi/trunk/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/DefaultEscherRecordFactory.java Sun Jul 17 21:18:07 2016
@@ -85,12 +85,12 @@ public class DefaultEscherRecordFactory
         }
 
         Constructor<? extends EscherRecord> 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
         Map<Short, Constructor<? extends EscherRecord>> result = new HashMap<Short, Constructor<? extends EscherRecord>>();
         final Class<?>[] EMPTY_CLASS_ARRAY = new Class[0];
 
-        for (int i = 0; i < recClasses.length; i++) {
+        for (Class<?> recClass : recClasses) {
             @SuppressWarnings("unchecked")
-            Class<? extends EscherRecord> recCls = (Class<? extends EscherRecord>) recClasses[i];
+            Class<? extends EscherRecord> recCls = (Class<? extends EscherRecord>) recClass;
             short sid;
             try {
                 sid = recCls.getField("RECORD_ID").getShort(null);
@@ -126,7 +126,7 @@ public class DefaultEscherRecordFactory
             }
             Constructor<? extends EscherRecord> constructor;
             try {
-                constructor = recCls.getConstructor( EMPTY_CLASS_ARRAY );
+                constructor = recCls.getConstructor(EMPTY_CLASS_ARRAY);
             } catch (NoSuchMethodException e) {
                 throw new RuntimeException(e);
             }

Modified: poi/trunk/src/java/org/apache/poi/ddf/EscherComplexProperty.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/EscherComplexProperty.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/EscherComplexProperty.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/EscherComplexProperty.java Sun Jul 17 21:18:07 2016
@@ -112,9 +112,8 @@ public class EscherComplexProperty exten
 
         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 exten
 
     @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 + "</" + getClass().getSimpleName() + ">\n";
         //builder.append("\t").append(tab).append(dataStr);
-        builder.append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
-        return builder.toString();
     }
 }

Modified: poi/trunk/src/java/org/apache/poi/ddf/EscherOptRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/EscherOptRecord.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/EscherOptRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/EscherOptRecord.java Sun Jul 17 21:18:07 2016
@@ -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 Abs
 
         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("</").append(getClass().getSimpleName()).append(">\n");
-        return builder.toString();
-    }
 }

Modified: poi/trunk/src/java/org/apache/poi/ddf/EscherPropertyFactory.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/EscherPropertyFactory.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/EscherPropertyFactory.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/EscherPropertyFactory.java Sun Jul 17 21:18:07 2016
@@ -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<EscherProperty> 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");
                     }

Modified: poi/trunk/src/java/org/apache/poi/ddf/EscherRecord.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ddf/EscherRecord.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ddf/EscherRecord.java (original)
+++ poi/trunk/src/java/org/apache/poi/ddf/EscherRecord.java Sun Jul 17 21:18:07 2016
@@ -84,8 +84,7 @@ public abstract class EscherRecord imple
     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 imple
      * @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("<RecordId>0x").append(HexDump.toHex(_recordId)).append("</RecordId>\n")
-                .append(tab).append("\t").append("<Options>").append(_options).append("</Options>\n")
-                .append(tab).append("</").append(getClass().getSimpleName()).append(">\n");
-        return builder.toString();
+        return tab + "<" + getClass().getSimpleName() + ">\n" +
+                tab + "\t" + "<RecordId>0x" + HexDump.toHex(_recordId) + "</RecordId>\n" +
+                tab + "\t" + "<Options>" + _options + "</Options>\n" +
+                tab + "</" + getClass().getSimpleName() + ">\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(){

Modified: poi/trunk/src/java/org/apache/poi/dev/RecordGenerator.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/dev/RecordGenerator.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/dev/RecordGenerator.java (original)
+++ poi/trunk/src/java/org/apache/poi/dev/RecordGenerator.java Sun Jul 17 21:18:07 2016
@@ -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);

Modified: poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/MutablePropertySet.java Sun Jul 17 21:18:07 2016
@@ -97,7 +97,7 @@ public class MutablePropertySet extends
     /**
      * <p>The length of the property set stream header.</p>
      */
-    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
     {
         /* 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
             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();

Modified: poi/trunk/src/java/org/apache/poi/hpsf/PropertySet.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/PropertySet.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/PropertySet.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/PropertySet.java Sun Jul 17 21:18:07 2016
@@ -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
      * <p>The "byteOrder" field must equal this value.</p>
      */
     static final byte[] BYTE_ORDER_ASSERTION =
-        new byte[] {(byte) 0xFE, (byte) 0xFF};
+            {(byte) 0xFE, (byte) 0xFF};
 
     /**
      * <p>Specifies this {@link PropertySet}'s byte order. See the
@@ -86,7 +87,7 @@ public class PropertySet
      * <p>The "format" field must equal this value.</p>
      */
     static final byte[] FORMAT_ASSERTION =
-        new byte[]{(byte) 0x00, (byte) 0x00};
+            {(byte) 0x00, (byte) 0x00};
 
     /**
      * <p>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 <code>true</code> if the objects are equal, <code>false</code>
      * 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('[');

Modified: poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java (original)
+++ poi/trunk/src/java/org/apache/poi/hpsf/extractor/HPSFPropertiesExtractor.java Sun Jul 17 21:18:07 2016
@@ -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 ext
         }
 
         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 ext
         // Now custom ones
         CustomProperties cps = dsi == null ? null : dsi.getCustomProperties();
         if (cps != null) {
-            Iterator<String> 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 ext
             return "";
         }
 
-        StringBuffer text = new StringBuffer();
+        StringBuilder text = new StringBuilder();
 
         PropertyIDMap idMap = ps.getPropertySetIDMap();
         Property[] props = ps.getProperties();
-        for (int i=0; i<props.length; i++) {
-            String type = Long.toString( props[i].getID() );
-            Object typeObj = idMap.get(props[i].getID());
-            if(typeObj != null) {
+        for (Property prop : props) {
+            String type = Long.toString(prop.getID());
+            Object typeObj = idMap.get(prop.getID());
+            if (typeObj != null) {
                 type = typeObj.toString();
             }
 
-            String val = HelperPropertySet.getPropertyValueText( props[i].getValue() );
-            text.append(type + " = " + val + "\n");
+            String val = HelperPropertySet.getPropertyValueText(prop.getValue());
+            text.append(type).append(" = ").append(val).append("\n");
         }
 
         return text.toString();
@@ -127,7 +124,7 @@ public class HPSFPropertiesExtractor ext
     public POITextExtractor getMetadataTextExtractor() {
         throw new IllegalStateException("You already have the Metadata Text Extractor, not recursing!");
     }
-    
+
     private static abstract class HelperPropertySet extends SpecialPropertySet {
         public HelperPropertySet() {
             super(null);
@@ -140,6 +137,16 @@ public class HPSFPropertiesExtractor ext
         }
     }
 
+    @Override
+    public boolean equals(Object o) {
+        return super.equals(o);
+    }
+
+    @Override
+    public int hashCode() {
+        return super.hashCode();
+    }
+
     public static void main(String[] args) throws IOException {
         for (String file : args) {
             HPSFPropertiesExtractor ext = new HPSFPropertiesExtractor(

Modified: poi/trunk/src/java/org/apache/poi/ss/formula/LazyAreaEval.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/formula/LazyAreaEval.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/formula/LazyAreaEval.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/formula/LazyAreaEval.java Sun Jul 17 21:18:07 2016
@@ -77,15 +77,13 @@ final class LazyAreaEval extends AreaEva
 	public String toString() {
 		CellReference crA = new CellReference(getFirstRow(), getFirstColumn());
 		CellReference crB = new CellReference(getLastRow(), getLastColumn());
-		StringBuffer sb = new StringBuffer();
-		sb.append(getClass().getName()).append("[");
-		sb.append(_evaluator.getSheetNameRange());
-		sb.append('!');
-		sb.append(crA.formatAsString());
-		sb.append(':');
-		sb.append(crB.formatAsString());
-		sb.append("]");
-		return sb.toString();
+		return getClass().getName() + "[" +
+				_evaluator.getSheetNameRange() +
+				'!' +
+				crA.formatAsString() +
+				':' +
+				crB.formatAsString() +
+				"]";
 	}
 
     /**

Modified: poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java (original)
+++ poi/trunk/src/java/org/apache/poi/ss/usermodel/DataFormatter.java Sun Jul 17 21:18:07 2016
@@ -33,7 +33,6 @@ import java.text.SimpleDateFormat;
 import java.util.ArrayList;
 import java.util.Date;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
 import java.util.Map;
@@ -319,7 +318,7 @@ public class DataFormatter implements Ob
         //  handle these ourselves in a special way.
         // For now, if we detect 3+ parts, we call out to CellFormat to handle it
         // TODO Going forward, we should really merge the logic between the two classes
-        if (formatStr.indexOf(";") != -1 && 
+        if (formatStr.contains(";") &&
                 formatStr.indexOf(';') != formatStr.lastIndexOf(';')) {
             try {
                 // Ask CellFormat to get a formatter for it
@@ -402,11 +401,9 @@ public class DataFormatter implements Ob
             String match = m.group();
             String symbol = match.substring(match.indexOf('$') + 1, match.indexOf('-'));
             if (symbol.indexOf('$') > -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 Ob
             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 Ob
             Excel displays the month instead of minutes."
           */
 
-        StringBuffer sb = new StringBuffer();
+        StringBuilder sb = new StringBuilder();
         char[] chars = formatStr.toCharArray();
         boolean mIsMonth = true;
         List<Integer> ms = new ArrayList<Integer>();
@@ -565,7 +562,7 @@ public class DataFormatter implements Ob
                 // 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 Ob
     }
 
     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 Ob
      * @see java.text.Format#format
      */
     public void setDefaultNumberFormat(Format format) {
-        Iterator<Map.Entry<String,Format>> itr = formats.entrySet().iterator();
-        while(itr.hasNext()) {
-            Map.Entry<String,Format> entry = itr.next();
+        for (Map.Entry<String, Format> entry : formats.entrySet()) {
             if (entry.getValue() == generalNumberFormat) {
                 entry.setValue(format);
             }
@@ -1054,11 +1049,9 @@ public class DataFormatter implements Ob
         /** 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 Ob
         /** 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 Ob
         /** 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 Ob
             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);

Modified: poi/trunk/src/java/org/apache/poi/util/HexRead.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/java/org/apache/poi/util/HexRead.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/java/org/apache/poi/util/HexRead.java (original)
+++ poi/trunk/src/java/org/apache/poi/util/HexRead.java Sun Jul 17 21:18:07 2016
@@ -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++ )
         {

Modified: poi/trunk/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java (original)
+++ poi/trunk/src/ooxml/java/org/apache/poi/xwpf/extractor/XWPFWordExtractor.java Sun Jul 17 21:18:07 2016
@@ -45,7 +45,7 @@ import org.openxmlformats.schemas.wordpr
  * 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 P
             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 P
         // 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) {

Modified: poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java (original)
+++ poi/trunk/src/ooxml/testcases/org/apache/poi/ss/formula/functions/TestProper.java Sun Jul 17 21:18:07 2016
@@ -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

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/extractor/TestExcelExtractor.java Sun Jul 17 21:18:07 2016
@@ -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<files.length; i++) {
-			ExcelExtractor extractor = createExtractor(files[i]);
+		for (String file : files) {
+			ExcelExtractor extractor = createExtractor(file);
 			String text = extractor.getText();
-			assertTrue("Unable to find expected word in text\n" + text, text.indexOf("testdoc") >=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();
 		}
 	}

Modified: poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/hssf/usermodel/TestHSSFDataFormatter.java Sun Jul 17 21:18:07 2016
@@ -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);
 //      }

Modified: poi/trunk/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/poifs/dev/TestPOIFSDump.java Sun Jul 17 21:18:07 2016
@@ -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",

Modified: poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java
URL: http://svn.apache.org/viewvc/poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java?rev=1753122&r1=1753121&r2=1753122&view=diff
==============================================================================
--- poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java (original)
+++ poi/trunk/src/testcases/org/apache/poi/ss/usermodel/TestDataFormatter.java Sun Jul 17 21:18:07 2016
@@ -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_-;_-$* \"-\"??_-;_-@_-"));
     }
 




---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@poi.apache.org
For additional commands, e-mail: commits-help@poi.apache.org