diff options
author | Axel Howind <axh@apache.org> | 2019-11-17 08:45:03 +0000 |
---|---|---|
committer | Axel Howind <axh@apache.org> | 2019-11-17 08:45:03 +0000 |
commit | 4f8879f8ef4f52a9d22c88718d58dae832706cb4 (patch) | |
tree | 58e4554eeeb3cded4a498b5bf6755d875d9f090d /src/java | |
parent | 10e0e3d108bc763f27db056c39285d24c6f068ab (diff) | |
download | poi-4f8879f8ef4f52a9d22c88718d58dae832706cb4.tar.gz poi-4f8879f8ef4f52a9d22c88718d58dae832706cb4.zip |
use zero size arg to toArray(), use Collection.addAll() (#63805, second patch)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1869919 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'src/java')
18 files changed, 30 insertions, 51 deletions
diff --git a/src/java/org/apache/poi/ddf/EscherDggRecord.java b/src/java/org/apache/poi/ddf/EscherDggRecord.java index 188a63ee57..89e133eca7 100644 --- a/src/java/org/apache/poi/ddf/EscherDggRecord.java +++ b/src/java/org/apache/poi/ddf/EscherDggRecord.java @@ -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]); } /** diff --git a/src/java/org/apache/poi/hpsf/Vector.java b/src/java/org/apache/poi/hpsf/Vector.java index d82c215b70..465eabd829 100644 --- a/src/java/org/apache/poi/hpsf/Vector.java +++ b/src/java/org/apache/poi/hpsf/Vector.java @@ -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(){ diff --git a/src/java/org/apache/poi/hssf/eventusermodel/EventWorkbookBuilder.java b/src/java/org/apache/poi/hssf/eventusermodel/EventWorkbookBuilder.java index f55189ea7d..165db0e8fd 100644 --- a/src/java/org/apache/poi/hssf/eventusermodel/EventWorkbookBuilder.java +++ b/src/java/org/apache/poi/hssf/eventusermodel/EventWorkbookBuilder.java @@ -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() { diff --git a/src/java/org/apache/poi/hssf/eventusermodel/HSSFRequest.java b/src/java/org/apache/poi/hssf/eventusermodel/HSSFRequest.java index 62c656ed08..1aca412806 100644 --- a/src/java/org/apache/poi/hssf/eventusermodel/HSSFRequest.java +++ b/src/java/org/apache/poi/hssf/eventusermodel/HSSFRequest.java @@ -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); } diff --git a/src/java/org/apache/poi/hssf/record/ExtSSTRecord.java b/src/java/org/apache/poi/hssf/record/ExtSSTRecord.java index e0b975d088..2ce2810e62 100644 --- a/src/java/org/apache/poi/hssf/record/ExtSSTRecord.java +++ b/src/java/org/apache/poi/hssf/record/ExtSSTRecord.java @@ -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) { diff --git a/src/java/org/apache/poi/hssf/record/GroupMarkerSubRecord.java b/src/java/org/apache/poi/hssf/record/GroupMarkerSubRecord.java index 575ed7a5af..47395f58bb 100644 --- a/src/java/org/apache/poi/hssf/record/GroupMarkerSubRecord.java +++ b/src/java/org/apache/poi/hssf/record/GroupMarkerSubRecord.java @@ -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; } } diff --git a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java index 7f8b345275..e4454bcf66 100644 --- a/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java +++ b/src/java/org/apache/poi/hssf/record/HyperlinkRecord.java @@ -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); diff --git a/src/java/org/apache/poi/hssf/record/PaletteRecord.java b/src/java/org/apache/poi/hssf/record/PaletteRecord.java index 162c67c514..9ec1c4708b 100644 --- a/src/java/org/apache/poi/hssf/record/PaletteRecord.java +++ b/src/java/org/apache/poi/hssf/record/PaletteRecord.java @@ -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) { diff --git a/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java b/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java index e32a74ba42..dc238a9625 100644 --- a/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java +++ b/src/java/org/apache/poi/hssf/record/aggregates/RowRecordsAggregate.java @@ -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 { diff --git a/src/java/org/apache/poi/hssf/usermodel/HSSFChart.java b/src/java/org/apache/poi/hssf/usermodel/HSSFChart.java index f91781dc64..c08511fa46 100644 --- a/src/java/org/apache/poi/hssf/usermodel/HSSFChart.java +++ b/src/java/org/apache/poi/hssf/usermodel/HSSFChart.java @@ -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; } diff --git a/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java b/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java index 7c74d47871..80db4b3c48 100644 --- a/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java +++ b/src/java/org/apache/poi/poifs/filesystem/POIFSDocumentPath.java @@ -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++) diff --git a/src/java/org/apache/poi/ss/format/CellFormat.java b/src/java/org/apache/poi/ss/format/CellFormat.java index 6c218d55b1..8d4d82fab9 100644 --- a/src/java/org/apache/poi/ss/format/CellFormat.java +++ b/src/java/org/apache/poi/ss/format/CellFormat.java @@ -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("@")) diff --git a/src/java/org/apache/poi/ss/formula/CollaboratingWorkbooksEnvironment.java b/src/java/org/apache/poi/ss/formula/CollaboratingWorkbooksEnvironment.java index bfd1f4e35b..57b13bf426 100644 --- a/src/java/org/apache/poi/ss/formula/CollaboratingWorkbooksEnvironment.java +++ b/src/java/org/apache/poi/ss/formula/CollaboratingWorkbooksEnvironment.java @@ -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) { diff --git a/src/java/org/apache/poi/ss/formula/FormulaCellCacheEntry.java b/src/java/org/apache/poi/ss/formula/FormulaCellCacheEntry.java index 63142e88b6..9dbb7248c8 100644 --- a/src/java/org/apache/poi/ss/formula/FormulaCellCacheEntry.java +++ b/src/java/org/apache/poi/ss/formula/FormulaCellCacheEntry.java @@ -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 +} diff --git a/src/java/org/apache/poi/ss/formula/functions/Subtotal.java b/src/java/org/apache/poi/ss/formula/functions/Subtotal.java index 8727353ae2..8d7084be83 100644 --- a/src/java/org/apache/poi/ss/formula/functions/Subtotal.java +++ b/src/java/org/apache/poi/ss/formula/functions/Subtotal.java @@ -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); } } diff --git a/src/java/org/apache/poi/ss/formula/functions/Trend.java b/src/java/org/apache/poi/ss/formula/functions/Trend.java index ec10277d7e..a6c3709344 100644 --- a/src/java/org/apache/poi/ss/formula/functions/Trend.java +++ b/src/java/org/apache/poi/ss/formula/functions/Trend.java @@ -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; } diff --git a/src/java/org/apache/poi/ss/util/CellRangeUtil.java b/src/java/org/apache/poi/ss/util/CellRangeUtil.java index 8c40a4d63a..3b8b5251d4 100644 --- a/src/java/org/apache/poi/ss/util/CellRangeUtil.java +++ b/src/java/org/apache/poi/ss/util/CellRangeUtil.java @@ -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; } diff --git a/src/java/org/apache/poi/util/HexRead.java b/src/java/org/apache/poi/util/HexRead.java index 1db930f25d..0acaef6e27 100644 --- a/src/java/org/apache/poi/util/HexRead.java +++ b/src/java/org/apache/poi/util/HexRead.java @@ -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(); |