]> source.dussan.org Git - poi.git/commitdiff
use zero size arg to toArray(), use Collection.addAll() (#63805, second patch)
authorAxel Howind <axh@apache.org>
Sun, 17 Nov 2019 08:45:03 +0000 (08:45 +0000)
committerAxel Howind <axh@apache.org>
Sun, 17 Nov 2019 08:45:03 +0000 (08:45 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1869919 13f79535-47bb-0310-9956-ffa450edef68

57 files changed:
src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java
src/examples/src/org/apache/poi/xslf/usermodel/ChartFromScratch.java
src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java
src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java
src/examples/src/org/apache/poi/xwpf/usermodel/examples/ChartFromScratch.java
src/java/org/apache/poi/ddf/EscherDggRecord.java
src/java/org/apache/poi/hpsf/Vector.java
src/java/org/apache/poi/hssf/eventusermodel/EventWorkbookBuilder.java
src/java/org/apache/poi/hssf/eventusermodel/HSSFRequest.java
src/java/org/apache/poi/hssf/record/ExtSSTRecord.java
src/java/org/apache/poi/hssf/record/GroupMarkerSubRecord.java
src/java/org/apache/poi/hssf/record/HyperlinkRecord.java
src/java/org/apache/poi/hssf/record/PaletteRecord.java
src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java
src/java/org/apache/poi/hssf/usermodel/HSSFChart.java
src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java
src/java/org/apache/poi/ss/format/CellFormat.java
src/java/org/apache/poi/ss/formula/CollaboratingWorkbooksEnvironment.java
src/java/org/apache/poi/ss/formula/FormulaCellCacheEntry.java
src/java/org/apache/poi/ss/formula/functions/Subtotal.java
src/java/org/apache/poi/ss/formula/functions/Trend.java
src/java/org/apache/poi/ss/util/CellRangeUtil.java
src/java/org/apache/poi/util/HexRead.java
src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java
src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java
src/ooxml/java/org/apache/poi/xssf/binary/XSSFBSheetHandler.java
src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormatting.java
src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java
src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java
src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java
src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java
src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java
src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java
src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java
src/scratchpad/src/org/apache/poi/hslf/record/Record.java
src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java
src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java
src/scratchpad/src/org/apache/poi/hslf/record/StyleTextProp9Atom.java
src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java
src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSoundData.java
src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/NameIdChunks.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java
src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java
src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java
src/scratchpad/src/org/apache/poi/hwpf/model/BookmarksTables.java
src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java
src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java
src/scratchpad/src/org/apache/poi/hwpf/model/OldFontTable.java
src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfCps.java
src/scratchpad/src/org/apache/poi/hwpf/usermodel/BookmarksImpl.java
src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java
src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java
src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java

index bd8ff14c4c552542f7b1d9a831b50709af660ab6..641b3d369c89d970ec27b14bfd1184406972c43d 100644 (file)
@@ -76,9 +76,9 @@ public class BarChartDemo {
                 listSpeakers.add(Double.valueOf(vals[1]));
                 listLanguages.add(vals[2]);
             }
-            String[] categories = listLanguages.toArray(new String[listLanguages.size()]);
-            Double[] values1 = listCountries.toArray(new Double[listCountries.size()]);
-            Double[] values2 = listSpeakers.toArray(new Double[listSpeakers.size()]);
+            String[] categories = listLanguages.toArray(new String[0]);
+            Double[] values1 = listCountries.toArray(new Double[0]);
+            Double[] values2 = listSpeakers.toArray(new Double[0]);
 
             try (XMLSlideShow pptx = new XMLSlideShow(argIS)) {
                 XSLFSlide slide = pptx.getSlides().get(0);
index 12f96fa6fd407334490124258255232e1f46739c..f30f03efbe68617613d12eb3d25766bea0dc0f44 100644 (file)
@@ -79,9 +79,9 @@ public class ChartFromScratch {
                 listLanguages.add(vals[2]);
             }
 
-            String[] categories = listLanguages.toArray(new String[listLanguages.size()]);
-            Double[] values1 = listCountries.toArray(new Double[listCountries.size()]);
-            Double[] values2 = listSpeakers.toArray(new Double[listSpeakers.size()]);
+            String[] categories = listLanguages.toArray(new String[0]);
+            Double[] values1 = listCountries.toArray(new Double[0]);
+            Double[] values2 = listSpeakers.toArray(new Double[0]);
 
             try {
 
index 1cc8aa2b104c34a6d3ddbe980bb4d35f05256915..749ed982181559a5effc686a1a4b50e6154630be 100644 (file)
@@ -89,8 +89,8 @@ public class PieChartDemo {
                        listCategories.add(vals[0]);
                        listValues.add(Double.valueOf(vals[1]));
                    }
-                   String[] categories = listCategories.toArray(new String[listCategories.size()]);
-                   Double[] values = listValues.toArray(new Double[listValues.size()]);
+                   String[] categories = listCategories.toArray(new String[0]);
+                   Double[] values = listValues.toArray(new Double[0]);
 
                    final int numOfPoints = categories.length;
                    final String categoryDataRange = chart.formatRange(new CellRangeAddress(1, numOfPoints, 0, 0));
index 731b732f8dc8ef6b4243fea8b0e7c5378b4f96d4..567d39a10258eeef119a9f69fe3866898c13e87f 100644 (file)
@@ -78,9 +78,9 @@ public class BarChartExample {
                 listSpeakers.add(Double.valueOf(vals[1]));
                 listLanguages.add(vals[2]);
             }
-            String[] categories = listLanguages.toArray(new String[listLanguages.size()]);
-            Double[] values1 = listCountries.toArray(new Double[listCountries.size()]);
-            Double[] values2 = listSpeakers.toArray(new Double[listSpeakers.size()]);
+            String[] categories = listLanguages.toArray(new String[0]);
+            Double[] values1 = listCountries.toArray(new Double[0]);
+            Double[] values2 = listSpeakers.toArray(new Double[0]);
 
             try (XWPFDocument doc = new XWPFDocument(argIS)) {
                 XWPFChart chart = doc.getCharts().get(0);
index 4a1a78150f40844933e2d1232851d309fa01b2c7..ee5624fd5764fb16d681c0931e260badf9bc6349 100644 (file)
@@ -80,9 +80,9 @@ public class ChartFromScratch {
                 listLanguages.add(vals[2]);
             }
 
-            String[] categories = listLanguages.toArray(new String[listLanguages.size()]);
-            Double[] values1 = listCountries.toArray(new Double[listCountries.size()]);
-            Double[] values2 = listSpeakers.toArray(new Double[listSpeakers.size()]);
+            String[] categories = listLanguages.toArray(new String[0]);
+            Double[] values1 = listCountries.toArray(new Double[0]);
+            Double[] values2 = listSpeakers.toArray(new Double[0]);
 
             try (XWPFDocument doc = new XWPFDocument()) {
                 XWPFChart chart = doc.createChart(XDDFChart.DEFAULT_WIDTH, XDDFChart.DEFAULT_HEIGHT);
index 188a63ee57c23e28fe915cfa099255b902bf42ff..89e133eca7409fada3b3681b43bf01dc5f743851 100644 (file)
@@ -219,7 +219,7 @@ public final class EscherDggRecord extends EscherRecord {
      * @return the file id clusters
      */
     public FileIdCluster[] getFileIdClusters() {
-        return field_5_fileIdClusters.toArray(new FileIdCluster[field_5_fileIdClusters.size()]);
+        return field_5_fileIdClusters.toArray(new FileIdCluster[0]);
     }
 
     /**
index d82c215b70d0e2fd9d7a239f3abeddcf6e77e54f..465eabd829c8060762715260aaa5c3e60ed5cd59 100644 (file)
@@ -58,7 +58,7 @@ public class Vector {
             }
             values.add(value);
         }
-        _values = values.toArray(new TypedPropertyValue[values.size()]);
+        _values = values.toArray(new TypedPropertyValue[0]);
     }
 
     public TypedPropertyValue[] getValues(){
index f55189ea7d8f861a0cd95e5632301fec8b637039..165db0e8fd7e87d46ea6cd5f4310e36b1a98e946 100644 (file)
@@ -17,6 +17,7 @@
 package org.apache.poi.hssf.eventusermodel;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.poi.hssf.model.HSSFFormulaParser;
@@ -69,9 +70,7 @@ public class EventWorkbookBuilder {
 
                // Core Workbook records go first
                if(bounds != null) {
-                       for (BoundSheetRecord bound : bounds) {
-                               wbRecords.add(bound);
-                       }
+                       Collections.addAll(wbRecords, bounds);
                }
                if(sst != null) {
                        wbRecords.add(sst);
@@ -82,9 +81,7 @@ public class EventWorkbookBuilder {
                if(externs != null) {
                        wbRecords.add(SupBookRecord.createInternalReferences(
                                        (short)externs.length));
-                       for (ExternSheetRecord extern : externs) {
-                               wbRecords.add(extern);
-                       }
+                       Collections.addAll(wbRecords, externs);
                }
 
                // Finally we need an EoF record
@@ -125,12 +122,12 @@ public class EventWorkbookBuilder {
 
                public BoundSheetRecord[] getBoundSheetRecords() {
                        return boundSheetRecords.toArray(
-                                       new BoundSheetRecord[boundSheetRecords.size()]
+                                       new BoundSheetRecord[0]
                        );
                }
                public ExternSheetRecord[] getExternSheetRecords() {
                        return externSheetRecords.toArray(
-                                       new ExternSheetRecord[externSheetRecords.size()]
+                                       new ExternSheetRecord[0]
                        );
                }
                public SSTRecord getSSTRecord() {
index 62c656ed088e52391dac77b13c496273a5d9ef7d..1aca412806ff4ee9d3073947e2cbe3c888f5ccab 100644 (file)
@@ -55,12 +55,9 @@ public class HSSFRequest {
         *        for example req.addListener(myListener, BOFRecord.sid)
         */
        public void addListener(HSSFListener lsnr, short sid) {
-               List<HSSFListener> list = _records.get(Short.valueOf(sid));
+               List<HSSFListener> list = _records.computeIfAbsent(Short.valueOf(sid), k -> new ArrayList<>(1));
 
-               if (list == null) {
-                       list = new ArrayList<>(1); // probably most people will use one listener
-                       _records.put(Short.valueOf(sid), list);
-               }
+               // probably most people will use one listener
                list.add(lsnr);
        }
 
index e0b975d0880fbbe9752ed5a1794dd3fa4f9ae6a7..2ce2810e62cf1e6f4c6a43aa542e9599a70d8dde 100644 (file)
@@ -103,7 +103,7 @@ public final class ExtSSTRecord extends ContinuableRecord {
                 in.nextRecord();
             }
         }
-        _sstInfos = lst.toArray(new InfoSubRecord[lst.size()]);
+        _sstInfos = lst.toArray(new InfoSubRecord[0]);
     }
 
     public void setNumStringsPerBucket(short numStrings) {
index 575ed7a5af91a71658288df4c074cab44eec5c42..47395f58bb3d2d92b2123d72c072df4d3243b011 100644 (file)
@@ -77,8 +77,7 @@ public final class GroupMarkerSubRecord extends SubRecord implements Cloneable {
     public GroupMarkerSubRecord clone() {
         GroupMarkerSubRecord rec = new GroupMarkerSubRecord();
         rec.reserved = new byte[reserved.length];
-        for ( int i = 0; i < reserved.length; i++ )
-            rec.reserved[i] = reserved[i];
+        System.arraycopy(reserved, 0, rec.reserved, 0, reserved.length);
         return rec;
     }
 }
index 7f8b345275ff1cffc7a6fe3a6d059f79261244fb..e4454bcf66938da4f58e34577ce0301b45d64ec9 100644 (file)
@@ -159,9 +159,7 @@ public final class HyperlinkRecord extends StandardRecord implements Cloneable {
                        int d0 = (parseShort(cc, 0) << 16) + (parseShort(cc, 4) << 0);
                        int d1 = parseShort(cc, 9);
                        int d2 = parseShort(cc, 14);
-                       for (int i = 23; i > 19; i--) {
-                               cc[i] = cc[i - 1];
-                       }
+            System.arraycopy(cc, 19, cc, 20, 4);
                        long d3 = parseLELong(cc, 20);
 
                        return new GUID(d0, d1, d2, d3);
index 162c67c514adc883bd0ade25ef25211db1f10594..9ec1c4708b6aa2eb59ced823dac8d3c613429702 100644 (file)
@@ -18,6 +18,7 @@
 package org.apache.poi.hssf.record;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 import org.apache.poi.util.LittleEndianOutput;
@@ -40,9 +41,7 @@ public final class PaletteRecord extends StandardRecord {
     public PaletteRecord() {
       PColor[] defaultPalette = createDefaultPalette();
       _colors    = new ArrayList<>(defaultPalette.length);
-      for (PColor element : defaultPalette) {
-        _colors.add(element);
-      }
+      Collections.addAll(_colors, defaultPalette);
     }
 
     public PaletteRecord(RecordInputStream in) {
index e32a74ba42228d678029e7d83c7d284842975f45..dc238a96252e7fae80143161c64297155deaeb0b 100644 (file)
@@ -195,7 +195,7 @@ public final class RowRecordsAggregate extends RecordAggregate {
         int startIndex = block * DBCellRecord.BLOCK_SIZE;
 
         if (_rowRecordValues == null) {
-            _rowRecordValues = _rowRecords.values().toArray(new RowRecord[_rowRecords.size()]);
+            _rowRecordValues = _rowRecords.values().toArray(new RowRecord[0]);
         }
 
         try {
@@ -212,7 +212,7 @@ public final class RowRecordsAggregate extends RecordAggregate {
             endIndex = _rowRecords.size()-1;
 
         if (_rowRecordValues == null){
-            _rowRecordValues = _rowRecords.values().toArray(new RowRecord[_rowRecords.size()]);
+            _rowRecordValues = _rowRecords.values().toArray(new RowRecord[0]);
         }
 
         try {
index f91781dc644fdff18305bd3483b4def5b3f2a161..c08511fa466e2e48603d8dd07a6e1464237979b9 100644 (file)
@@ -273,7 +273,7 @@ public final class HSSFChart {
                        }
                }
 
-               return charts.toArray( new HSSFChart[charts.size()] );
+               return charts.toArray(new HSSFChart[0]);
        }
 
        /** Get the X offset of the chart */
@@ -298,7 +298,7 @@ public final class HSSFChart {
         * Returns the series of the chart
         */
        public HSSFSeries[] getSeries() {
-               return series.toArray(new HSSFSeries[series.size()]);
+               return series.toArray(new HSSFSeries[0]);
        }
 
        /**
@@ -1153,7 +1153,7 @@ public final class HSSFChart {
                                }
                        }
                        
-                       linkedDataRecord.setFormulaOfLink(ptgList.toArray(new Ptg[ptgList.size()]));
+                       linkedDataRecord.setFormulaOfLink(ptgList.toArray(new Ptg[0]));
                        
                        return rowCount * colCount;
                }
index 7c74d47871bd22ba062cd290a4caa3c14943af56..80db4b3c487cb24c259d1dce09e99d3874dead51 100644 (file)
@@ -122,10 +122,7 @@ public class POIFSDocumentPath
             this.components =
                 new String[ path.components.length + components.length ];
         }
-        for (int j = 0; j < path.components.length; j++)
-        {
-            this.components[ j ] = path.components[ j ];
-        }
+        System.arraycopy(path.components, 0, this.components, 0, path.components.length);
         if (components != null)
         {
             for (int j = 0; j < components.length; j++)
index 6c218d55b10a35b95283a06803efce481e7ed32e..8d4d82fab93a5ba94885a50b1951644dec040626 100644 (file)
@@ -154,11 +154,7 @@ public class CellFormat {
      * @return A {@link CellFormat} that applies the given format.
      */
     public static synchronized CellFormat getInstance(Locale locale, String format) {
-        Map<String, CellFormat> formatMap = formatCache.get(locale);
-        if (formatMap == null) {
-            formatMap = new WeakHashMap<>();
-            formatCache.put(locale, formatMap);
-        }
+        Map<String, CellFormat> formatMap = formatCache.computeIfAbsent(locale, k -> new WeakHashMap<>());
         CellFormat fmt = formatMap.get(format);
         if (fmt == null) {
             if (format.equals("General") || format.equals("@"))
index bfd1f4e35b1b8613b3bfa1b23d7940b298f80144..57b13bf426d8f8d6105647ffe9609b0be2cc5b1e 100644 (file)
@@ -71,7 +71,7 @@ public final class CollaboratingWorkbooksEnvironment {
             throw new IllegalArgumentException("Must provide at least one collaborating worbook");
         }
         WorkbookEvaluator[] evaluators = 
-                evaluatorsByName.values().toArray(new WorkbookEvaluator[evaluatorsByName.size()]); 
+                evaluatorsByName.values().toArray(new WorkbookEvaluator[0]); 
         new CollaboratingWorkbooksEnvironment(evaluatorsByName, evaluators);
     }
     public static void setupFormulaEvaluator(Map<String,FormulaEvaluator> evaluators) {
index 63142e88b63125197587cfdac7fea5a26158ad99..9dbb7248c802ca7ebd4c693ec3d2a242c8285286 100644 (file)
@@ -17,6 +17,7 @@
 
 package org.apache.poi.ss.formula;
 
+import java.util.Arrays;
 import java.util.Collections;
 import java.util.HashSet;
 import java.util.Set;
@@ -94,9 +95,7 @@ final class FormulaCellCacheEntry extends CellCacheEntry {
                        usedSet = Collections.emptySet();
                } else {
                        usedSet = new HashSet<>(nUsed * 3 / 2);
-                       for (int i = 0; i < nUsed; i++) {
-                               usedSet.add(usedCells[i]);
-                       }
+                       usedSet.addAll(Arrays.asList(usedCells).subList(0, nUsed));
                }
                for (int i = 0; i < nPrevUsed; i++) {
                        CellCacheEntry prevUsed = prevUsedCells[i];
@@ -121,4 +120,4 @@ final class FormulaCellCacheEntry extends CellCacheEntry {
                        }
                }
        }
-}
\ No newline at end of file
+}
index 8727353ae2716e746755d49e4981fd9e3d1dad62..8d7084be833184fa26168153bb470d7ea41af232 100644 (file)
@@ -141,6 +141,6 @@ public class Subtotal implements Function {
                        }
                }
 
-               return innerFunc.evaluate(list.toArray(new ValueEval[list.size()]), srcRowIndex, srcColumnIndex);
+               return innerFunc.evaluate(list.toArray(new ValueEval[0]), srcRowIndex, srcColumnIndex);
        }
 }
index ec10277d7e4e8bdc2276c9638f6f7f7d3aac3212..a6c3709344c9b8c0ccf5db62c2a34bd45a049512 100644 (file)
@@ -149,9 +149,7 @@ public final class Trend implements Function {
         }
         double[] oneD = new double[twoD.length * twoD[0].length];
         for (int i = 0; i < twoD.length; i++) {
-            for (int j = 0; j < twoD[0].length; j++) {
-                oneD[i * twoD[0].length + j] = twoD[i][j];
-            }
+            System.arraycopy(twoD[i], 0, oneD, i * twoD[0].length + 0, twoD[0].length);
         }
         return oneD;
     }
index 8c40a4d63a000e25ee4b96a85f86a522eefd7b1a..3b8b5251d4b5223ca5e6e6363ac708bf30fb0bcd 100644 (file)
@@ -18,6 +18,7 @@
 package org.apache.poi.ss.util;
 
 import java.util.ArrayList;
+import java.util.Collections;
 import java.util.List;
 
 /**
@@ -173,9 +174,7 @@ public final class CellRangeUtil {
     }
     private static List<CellRangeAddress> toList(CellRangeAddress[] temp) {
         List<CellRangeAddress> result = new ArrayList<>(temp.length);
-        for (CellRangeAddress range : temp) {
-            result.add(range);
-        }
+        Collections.addAll(result, temp);
         return result;
     }
 
index 1db930f25d11a6b6188cd32738b70dbb6b519a47..0acaef6e278c576b32817af8612cfb61af754b7f 100644 (file)
@@ -125,7 +125,7 @@ public class HexRead {
                 }
             }
         }
-        Byte[] polished = bytes.toArray(new Byte[bytes.size()]);
+        Byte[] polished = bytes.toArray(new Byte[0]);
         byte[] rval = new byte[polished.length];
         for ( int j = 0; j < polished.length; j++ ) {
             rval[j] = polished[j].byteValue();
index fefae87a894c2197c29a6c2695e579432f3d84c9..7cee2a01873e7740bab3f52975a3fd7367e988f6 100644 (file)
@@ -125,9 +125,7 @@ public class RelationshipTransformService extends TransformService {
             throw new InvalidAlgorithmParameterException();
         }
         RelationshipTransformParameterSpec relParams = (RelationshipTransformParameterSpec) params;
-        for (String sourceId : relParams.sourceIds) {
-            this.sourceIds.add(sourceId);
-        }
+        this.sourceIds.addAll(relParams.sourceIds);
     }
 
     @Override
index 7903c9c5703b8457fb48eac3632629523e7e0547..ebab4c5f236abea403652207a910fe17b209fedc 100644 (file)
@@ -365,7 +365,7 @@ public class XDDFTextRun {
             .map(font -> new XDDFFont(FontGroup.SYMBOL, font))
             .ifPresent(font -> list.add(font));
 
-        return list.toArray(new XDDFFont[list.size()]);
+        return list.toArray(new XDDFFont[0]);
     }
 
     /**
index 726c2eeb897b58d2062b33866302d59a503d32d0..b726545daf341c27ed8e82d8794c5fa9ddd4de05 100644 (file)
@@ -312,9 +312,7 @@ public class XSSFBSheetHandler extends XSSFBParser {
         b0 &= ~(1<<1);
 
         rkBuffer[4] = b0;
-        for (int i = 1; i < 4; i++) {
-            rkBuffer[i+4] = data[offset+i];
-        }
+        System.arraycopy(data, offset + 1, rkBuffer, 5, 3);
         double d = 0.0;
         if (floatingPoint) {
             d = LittleEndian.getDouble(rkBuffer);
index 671e781c82b547828337bee98f7cc1eb35218954..eff8e375b4a78ca7a16b1def224263c1d2e86a03 100644 (file)
@@ -61,7 +61,7 @@ public class XSSFConditionalFormatting implements ConditionalFormatting {
                 lst.add(CellRangeAddress.valueOf(region));
             }
         }
-        return lst.toArray(new CellRangeAddress[lst.size()]);
+        return lst.toArray(new CellRangeAddress[0]);
     }
 
     @Override
index 884cc8ef119dc32d98f1cb9735f4e8da29095c93..994deb6dafa49d417ff5052a993ad4b304090d4e 100644 (file)
@@ -445,7 +445,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
     }
 
     public XWPFHyperlink[] getHyperlinks() {
-        return hyperlinks.toArray(new XWPFHyperlink[hyperlinks.size()]);
+        return hyperlinks.toArray(new XWPFHyperlink[0]);
     }
 
     public XWPFComment getCommentByID(String id) {
@@ -459,7 +459,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
     }
 
     public XWPFComment[] getComments() {
-        return comments.toArray(new XWPFComment[comments.size()]);
+        return comments.toArray(new XWPFComment[0]);
     }
 
     /**
@@ -1423,11 +1423,7 @@ public class XWPFDocument extends POIXMLDocument implements Document, IBody {
     }
 
     void registerPackagePictureData(XWPFPictureData picData) {
-        List<XWPFPictureData> list = packagePictures.get(picData.getChecksum());
-        if (list == null) {
-            list = new ArrayList<>(1);
-            packagePictures.put(picData.getChecksum(), list);
-        }
+        List<XWPFPictureData> list = packagePictures.computeIfAbsent(picData.getChecksum(), k -> new ArrayList<>(1));
         if (!list.contains(picData)) {
             list.add(picData);
         }
index c63a0493a35845f73e676c52f9355bc485f6e4cb..56417bce75ffef7314e4459007e86fe6a573fb94 100644 (file)
@@ -258,7 +258,7 @@ public final class Chunk {
 
                // Save the commands we liked the look of
                this.commands = commandList.toArray(
-                                                       new Command[commandList.size()] );
+                new Command[0]);
 
                // Now build up the blocks, if we had a command that tells
                //  us where a block is
index e1ac0e8ad8163d2dd6d9f95378d7df338db398dd..b43a0a10e17f6942d0e14a84fd5ba6d6644e7d65 100644 (file)
@@ -109,7 +109,7 @@ public final class ChunkFactory {
                                defsL.add(def);
                        }
     
-                       CommandDefinition[] defs = defsL.toArray(new CommandDefinition[defsL.size()]);
+                       CommandDefinition[] defs = defsL.toArray(new CommandDefinition[0]);
     
                        // Add to the map
                        chunkCommandDefinitions.put(Integer.valueOf(chunkType), defs);
index 4c0c890f9340d9af60ce0bcdd1223425c3287424..a669a0af527f0145b3d5fec452bd6e0b3c5eda17 100644 (file)
@@ -76,6 +76,6 @@ public final class ChunkStream extends Stream {
                        logger.log(POILogger.ERROR, "Failed to create chunk at " + pos + ", ignoring rest of data." + e);
                }
 
-               chunks = chunksA.toArray(new Chunk[chunksA.size()]);
+               chunks = chunksA.toArray(new Chunk[0]);
        }
 }
index 505ad50a2fd257ae799688f96b66b0847ba2c534..47b16b7d4e63333230c8fa20247d1580bbb7b1bb 100644 (file)
@@ -57,7 +57,7 @@ public abstract class EscherPart extends HPBFPart {
                        ec.add(er);
                }
 
-               records = ec.toArray(new EscherRecord[ec.size()]);
+               records = ec.toArray(new EscherRecord[0]);
        }
 
        public EscherRecord[] getEscherRecords() {
index ced5508a9d559ca5c2b1774f9ef3eefbf7163218..1c5fb4c4c4599fabae6ba1ed71044420b7f0a5a9 100644 (file)
@@ -50,7 +50,7 @@ public class ExObjList extends RecordContainer {
                        }
                }
 
-               return links.toArray(new ExHyperlink[links.size()]);
+               return links.toArray(new ExHyperlink[0]);
        }
 
        /** 
index 4dd0f3f033f7d84a088f88a3d675a896e54a8064..8451193c3372c3ae3608ffeb4a17fa4e805b54a1 100644 (file)
@@ -82,8 +82,8 @@ public final class MainMaster extends SheetContainer {
                        }
 
                }
-               txmasters = tx.toArray(new TxMasterStyleAtom[tx.size()]);
-               clrscheme = clr.toArray(new ColorSchemeAtom[clr.size()]);
+               txmasters = tx.toArray(new TxMasterStyleAtom[0]);
+               clrscheme = clr.toArray(new ColorSchemeAtom[0]);
        }
 
        /**
index c4ec8c983f5699ffcb8f3b21c4efd9a1e65a8069..fb241568fb288e18169870fad88bcdaab9dbd94c 100644 (file)
@@ -149,7 +149,7 @@ public abstract class Record implements GenericRecord
                }
 
                // Turn the vector into an array, and return
-        return children.toArray( new Record[children.size()] );
+        return children.toArray(new Record[0]);
        }
 
        /**
index f7cf20107b7d9d58f727eda2f4d7c6c2f79ee08d..546c07691b96ddad55c228c576a8df758a3c36bf 100644 (file)
@@ -150,7 +150,7 @@ public abstract class RecordContainer extends Record
                 rm = r;
             }
         }
-        _children = lst.toArray(new Record[lst.size()]);
+        _children = lst.toArray(new Record[0]);
         return rm;
     }
 
index 0c6e825d9bdef2e1dcea44f658b21590575286d1..268145d31cbc298f7d2ef6e5c73054154cf39997 100644 (file)
@@ -107,7 +107,7 @@ public final class SlideListWithText extends RecordContainer {
                }
 
                // Turn the list into an array
-               slideAtomsSets = sets.toArray( new SlideAtomsSet[sets.size()] );
+               slideAtomsSets = sets.toArray(new SlideAtomsSet[0]);
        }
 
        /**
index d11f406faeddcaeefa24286826935904b1dd7b3b..cedea7f646e92043766e6d09ab43e1d79f53db5b 100644 (file)
@@ -91,7 +91,7 @@ public final class StyleTextProp9Atom extends RecordAtom {
                 break;
             }
         }
-        this.autoNumberSchemes = schemes.toArray(new TextPFException9[schemes.size()]);
+        this.autoNumberSchemes = schemes.toArray(new TextPFException9[0]);
     }
 
     /**
@@ -155,4 +155,4 @@ public final class StyleTextProp9Atom extends RecordAtom {
             "autoNumberSchemes", this::getAutoNumberTypes
         );
     }
-}
\ No newline at end of file
+}
index 115dc21e4cb34ba80822df05ce916fddc24a8c61..d5722906573f3cb9395b513a7400a24a21b4b194 100644 (file)
@@ -177,7 +177,7 @@ public final class TextSpecInfoAtom extends RecordAtom {
         while (bis.getReadIndex() < _data.length) {
             lst.add(new TextSpecInfoRun(bis));
         }
-        return lst.toArray(new TextSpecInfoRun[lst.size()]);
+        return lst.toArray(new TextSpecInfoRun[0]);
     }
 
     @Override
index 63977ccc23c7bee885c07a85e3473e9737dd992f..4ab01f0b3162e5ed736fd413e39f8868eade407f 100644 (file)
@@ -452,7 +452,7 @@ public class HSLFSlideShowEncrypted implements Closeable {
             recordMap.remove(oldOffset);
         }
 
-        return recordMap.values().toArray(new Record[recordMap.size()]);
+        return recordMap.values().toArray(new Record[0]);
     }
 
 
@@ -496,7 +496,7 @@ public class HSLFSlideShowEncrypted implements Closeable {
 
         uea.setMaxPersistWritten(maxSlideId);
 
-        records = recordList.toArray(new Record[recordList.size()]);
+        records = recordList.toArray(new Record[0]);
 
         return records;
     }
index 51272e917f31d4485edd82731e4e8a07b580a88c..ad0762de7a8ea5607d972f4b0e216e400b7ab5dc 100644 (file)
@@ -89,6 +89,6 @@ public final class HSLFSoundData {
             }
 
         }
-        return lst.toArray(new HSLFSoundData[lst.size()]);
+        return lst.toArray(new HSLFSoundData[0]);
     }
 }
index 15a961ab661ea5c9c537d0147d7eb32f0c7cd06b..19d73610d760231e5af1f366f19218689310af3f 100644 (file)
@@ -167,8 +167,8 @@ public class MAPIMessage extends POIReadOnlyDocument {
             attachments.add( (AttachmentChunks)group );
          }
       }
-      attachmentChunks = attachments.toArray(new AttachmentChunks[attachments.size()]);
-      recipientChunks  = recipients.toArray(new RecipientChunks[recipients.size()]);
+      attachmentChunks = attachments.toArray(new AttachmentChunks[0]);
+      recipientChunks  = recipients.toArray(new RecipientChunks[0]);
 
       // Now sort these chunks lists so they're in ascending order,
       //  rather than in random filesystem order
index 9e31294c514830ba60afcdf06012c8d2eb96a800..70b5f6233a0d6ec7e09486ac4990073ce4fae27c 100644 (file)
@@ -98,7 +98,7 @@ public class AttachmentChunks implements ChunkGroup {
     }
 
     public Chunk[] getAll() {
-        return allChunks.toArray(new Chunk[allChunks.size()]);
+        return allChunks.toArray(new Chunk[0]);
     }
 
     @Override
index dacf09ed27d4961cd72f624b07683bbc0e35e822..c2014a50320288397dd78051bd0001a4e9bfe92b 100644 (file)
@@ -110,7 +110,7 @@ public final class Chunks implements ChunkGroupWithProperties {
         for (List<Chunk> c : allChunks.values()) {
             chunks.addAll(c);
         }
-        return chunks.toArray(new Chunk[chunks.size()]);
+        return chunks.toArray(new Chunk[0]);
     }
 
     public StringChunk getMessageClass() {
@@ -239,9 +239,7 @@ public final class Chunks implements ChunkGroupWithProperties {
         }
 
         // And add to the main list
-        if (allChunks.get(prop) == null) {
-            allChunks.put(prop, new ArrayList<>());
-        }
+        allChunks.computeIfAbsent(prop, k -> new ArrayList<>());
         allChunks.get(prop).add(chunk);
     }
 
@@ -254,4 +252,4 @@ public final class Chunks implements ChunkGroupWithProperties {
                     "Message didn't contain a root list of properties!");
         }
     }
-}
\ No newline at end of file
+}
index b41bcca83a6569c6271b3fea49ce1dc01ac5fb73..71fb2ef7df172369b70e3e8f265afc7a24c273c9 100644 (file)
@@ -30,7 +30,7 @@ public final class NameIdChunks implements ChunkGroup {
     private List<Chunk> allChunks = new ArrayList<>();
 
     public Chunk[] getAll() {
-        return allChunks.toArray(new Chunk[allChunks.size()]);
+        return allChunks.toArray(new Chunk[0]);
     }
 
     @Override
index e9241845fd5a983aa6c4fd4a73b770b8d3084c4d..aa6926ceef259ba16684b71a5518e618b6398a2a 100644 (file)
@@ -172,7 +172,7 @@ public final class RecipientChunks implements ChunkGroupWithProperties {
     }
 
     public Chunk[] getAll() {
-        return allChunks.toArray(new Chunk[allChunks.size()]);
+        return allChunks.toArray(new Chunk[0]);
     }
 
     @Override
index c16f7afae7cfbdb2e00e6b8ce39e3b74623b058e..980cf0a24b53d050618a37dcc5573478e177c6aa 100644 (file)
@@ -99,7 +99,7 @@ public final class POIFSChunkParser {
       }
       
       // Finish
-      return groups.toArray(new ChunkGroup[groups.size()]);
+      return groups.toArray(new ChunkGroup[0]);
    }
    
    /**
index 6792c358f9f0a1620866779987044dcf2e8a7eb9..6c1739728969d2990a37fee00cb6532180d059c7 100644 (file)
@@ -79,7 +79,7 @@ public class AbstractWordUtils
             }
         }
 
-        Integer[] sorted = edges.toArray( new Integer[edges.size()] );
+        Integer[] sorted = edges.toArray(new Integer[0]);
         int[] result = new int[sorted.length];
         for ( int i = 0; i < sorted.length; i++ )
         {
index 691273f41a741a526bce2ef120281956fe68a089..877b3639c80eb0d35096a3457641feb50506a4a7 100644 (file)
@@ -194,7 +194,7 @@ public class BookmarksTables
         }
 
         int start = tableStream.size();
-        SttbUtils.writeSttbfBkmk( names.toArray( new String[names.size()] ),
+        SttbUtils.writeSttbfBkmk( names.toArray(new String[0]),
                 tableStream );
         int end = tableStream.size();
 
index 9d62c9c52fd6718a75674c5612a477d1cc664f9e..ee6e15051db327d01deefdde759baf27102c9a1d 100644 (file)
@@ -61,7 +61,7 @@ public class ComplexFileTable {
             SprmBuffer sprmBuffer = new SprmBuffer(bs, false, 0);
             sprmBuffers.add(sprmBuffer);
         }
-        this._grpprls = sprmBuffers.toArray(new SprmBuffer[sprmBuffers.size()]);
+        this._grpprls = sprmBuffers.toArray(new SprmBuffer[0]);
 
         if (tableStream[offset] != TEXT_PIECE_TABLE_TYPE) {
             throw new IOException("The text piece table is corrupted");
index 67a74cea72c11a789b24d7c38dc1dd0038a47534..19256607a20eb391a362da0d680ebad05cc2a901 100644 (file)
@@ -84,7 +84,7 @@ public final class FSPATable
         {
             result.add( new FSPA( propertyNode.getBytes(), 0 ) );
         }
-        return result.toArray( new FSPA[result.size()] );
+        return result.toArray(new FSPA[0]);
     }
 
     public String toString()
index 28e6a04303474a00cf6e915b0ada885f1d1c60a2..814f0e39f619e57d966437a85b690f782fde39cc 100644 (file)
@@ -57,7 +57,7 @@ public final class OldFontTable {
             startOffset += oldFfn.getLength();
 
         }
-        _fontNames = ffns.toArray(new OldFfn[ffns.size()]);
+        _fontNames = ffns.toArray(new OldFfn[0]);
     }
 
 
index c838a1a21e0bd0dabe702d7c8a23d3f5ff843b05..54dc1afe52d180c8edd9bbc65f6e327a59e4a100 100644 (file)
@@ -163,7 +163,7 @@ public final class PlexOfCps {
         if (_props == null || _props.isEmpty())
             return new GenericPropertyNode[0];
 
-        return _props.toArray(new GenericPropertyNode[_props.size()]);
+        return _props.toArray(new GenericPropertyNode[0]);
     }
 
     @Override
index 8a80a743e55e7baf891d50b5e302034347a34641..24a7c8ff8d4dfcc767bc391f1ac785eea8df2d13 100644 (file)
@@ -231,12 +231,7 @@ public class BookmarksImpl implements Bookmarks
             GenericPropertyNode property = bookmarksTables
                     .getDescriptorFirst( b );
             Integer positionKey = Integer.valueOf( property.getStart() );
-            List<GenericPropertyNode> atPositionList = result.get( positionKey );
-            if ( atPositionList == null )
-            {
-                atPositionList = new LinkedList<>();
-                result.put( positionKey, atPositionList );
-            }
+            List<GenericPropertyNode> atPositionList = result.computeIfAbsent(positionKey, k -> new LinkedList<>());
             atPositionList.add( property );
         }
 
index 30c177f0866a7d3553614b6f2a51ecf05529da34..ba49c8cb5fbe3ef5939e6a864270539c5ea8744a 100644 (file)
@@ -235,6 +235,6 @@ public final class TestTxMasterStyleAtom extends TestCase {
             }
         }
 
-        return lst.toArray(new TxMasterStyleAtom[lst.size()]);
+        return lst.toArray(new TxMasterStyleAtom[0]);
     }
 }
index 305bc5f026c00017c2707e55fe165c60552fd3f4..5ce8df3cd0f0874947f62f5c4d6741ce6448a408 100644 (file)
@@ -74,7 +74,7 @@ public final class TestColumnInfoRecordsAggregate {
                public static ColumnInfoRecord[] getRecords(ColumnInfoRecordsAggregate agg) {
                        CIRCollector circ = new CIRCollector();
                        agg.visitContainedRecords(circ);
-            return circ._list.toArray(new ColumnInfoRecord[circ._list.size()]);
+            return circ._list.toArray(new ColumnInfoRecord[0]);
                }
        }
 
index 0ca030438184318aacfa2fd2c970c32016f367bc..aec1f20d6e95d99743a138011f9ed3377c415300 100644 (file)
@@ -49,10 +49,7 @@ public final class TestPOIFSDocumentPath extends TestCase {
         {
             String[] params = new String[ j ];
 
-            for (int k = 0; k < j; k++)
-            {
-                params[ k ] = components[ k ];
-            }
+            System.arraycopy(components, 0, params, 0, j);
             POIFSDocumentPath path = new POIFSDocumentPath(params);
 
             assertEquals(j, path.length());
@@ -116,10 +113,7 @@ public final class TestPOIFSDocumentPath extends TestCase {
         {
             String[] initialParams = new String[ n ];
 
-            for (int k = 0; k < n; k++)
-            {
-                initialParams[ k ] = initialComponents[ k ];
-            }
+            System.arraycopy(initialComponents, 0, initialParams, 0, n);
             POIFSDocumentPath base       =
                 new POIFSDocumentPath(initialParams);
             String[]          components =
@@ -131,10 +125,7 @@ public final class TestPOIFSDocumentPath extends TestCase {
             {
                 String[] params = new String[ j ];
 
-                for (int k = 0; k < j; k++)
-                {
-                    params[ k ] = components[ k ];
-                }
+                System.arraycopy(components, 0, params, 0, j);
                 POIFSDocumentPath path = new POIFSDocumentPath(base, params);
 
                 assertEquals(j + n, path.length());