From 4f8879f8ef4f52a9d22c88718d58dae832706cb4 Mon Sep 17 00:00:00 2001 From: Axel Howind Date: Sun, 17 Nov 2019 08:45:03 +0000 Subject: [PATCH] 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 --- .../apache/poi/xslf/usermodel/BarChartDemo.java | 6 +++--- .../poi/xslf/usermodel/ChartFromScratch.java | 6 +++--- .../apache/poi/xslf/usermodel/PieChartDemo.java | 4 ++-- .../xwpf/usermodel/examples/BarChartExample.java | 6 +++--- .../xwpf/usermodel/examples/ChartFromScratch.java | 6 +++--- src/java/org/apache/poi/ddf/EscherDggRecord.java | 2 +- src/java/org/apache/poi/hpsf/Vector.java | 2 +- .../hssf/eventusermodel/EventWorkbookBuilder.java | 13 +++++-------- .../poi/hssf/eventusermodel/HSSFRequest.java | 7 ++----- .../org/apache/poi/hssf/record/ExtSSTRecord.java | 2 +- .../poi/hssf/record/GroupMarkerSubRecord.java | 3 +-- .../apache/poi/hssf/record/HyperlinkRecord.java | 4 +--- .../org/apache/poi/hssf/record/PaletteRecord.java | 5 ++--- .../record/aggregates/RowRecordsAggregate.java | 4 ++-- .../org/apache/poi/hssf/usermodel/HSSFChart.java | 6 +++--- .../poi/poifs/filesystem/POIFSDocumentPath.java | 5 +---- src/java/org/apache/poi/ss/format/CellFormat.java | 6 +----- .../CollaboratingWorkbooksEnvironment.java | 2 +- .../poi/ss/formula/FormulaCellCacheEntry.java | 7 +++---- .../apache/poi/ss/formula/functions/Subtotal.java | 2 +- .../apache/poi/ss/formula/functions/Trend.java | 4 +--- .../org/apache/poi/ss/util/CellRangeUtil.java | 5 ++--- src/java/org/apache/poi/util/HexRead.java | 2 +- .../services/RelationshipTransformService.java | 4 +--- .../poi/xddf/usermodel/text/XDDFTextRun.java | 2 +- .../apache/poi/xssf/binary/XSSFBSheetHandler.java | 4 +--- .../xssf/usermodel/XSSFConditionalFormatting.java | 2 +- .../apache/poi/xwpf/usermodel/XWPFDocument.java | 10 +++------- .../src/org/apache/poi/hdgf/chunks/Chunk.java | 2 +- .../org/apache/poi/hdgf/chunks/ChunkFactory.java | 2 +- .../org/apache/poi/hdgf/streams/ChunkStream.java | 2 +- .../src/org/apache/poi/hpbf/model/EscherPart.java | 2 +- .../src/org/apache/poi/hslf/record/ExObjList.java | 2 +- .../org/apache/poi/hslf/record/MainMaster.java | 4 ++-- .../src/org/apache/poi/hslf/record/Record.java | 2 +- .../apache/poi/hslf/record/RecordContainer.java | 2 +- .../apache/poi/hslf/record/SlideListWithText.java | 2 +- .../poi/hslf/record/StyleTextProp9Atom.java | 4 ++-- .../apache/poi/hslf/record/TextSpecInfoAtom.java | 2 +- .../hslf/usermodel/HSLFSlideShowEncrypted.java | 4 ++-- .../apache/poi/hslf/usermodel/HSLFSoundData.java | 2 +- .../src/org/apache/poi/hsmf/MAPIMessage.java | 4 ++-- .../poi/hsmf/datatypes/AttachmentChunks.java | 2 +- .../src/org/apache/poi/hsmf/datatypes/Chunks.java | 8 +++----- .../apache/poi/hsmf/datatypes/NameIdChunks.java | 2 +- .../poi/hsmf/datatypes/RecipientChunks.java | 2 +- .../apache/poi/hsmf/parsers/POIFSChunkParser.java | 2 +- .../poi/hwpf/converter/AbstractWordUtils.java | 2 +- .../apache/poi/hwpf/model/BookmarksTables.java | 2 +- .../apache/poi/hwpf/model/ComplexFileTable.java | 2 +- .../src/org/apache/poi/hwpf/model/FSPATable.java | 2 +- .../org/apache/poi/hwpf/model/OldFontTable.java | 2 +- .../src/org/apache/poi/hwpf/model/PlexOfCps.java | 2 +- .../apache/poi/hwpf/usermodel/BookmarksImpl.java | 7 +------ .../poi/hslf/record/TestTxMasterStyleAtom.java | 2 +- .../TestColumnInfoRecordsAggregate.java | 2 +- .../poifs/filesystem/TestPOIFSDocumentPath.java | 15 +++------------ 57 files changed, 88 insertions(+), 133 deletions(-) diff --git a/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java b/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java index bd8ff14c4c..641b3d369c 100644 --- a/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java +++ b/src/examples/src/org/apache/poi/xslf/usermodel/BarChartDemo.java @@ -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); diff --git a/src/examples/src/org/apache/poi/xslf/usermodel/ChartFromScratch.java b/src/examples/src/org/apache/poi/xslf/usermodel/ChartFromScratch.java index 12f96fa6fd..f30f03efbe 100644 --- a/src/examples/src/org/apache/poi/xslf/usermodel/ChartFromScratch.java +++ b/src/examples/src/org/apache/poi/xslf/usermodel/ChartFromScratch.java @@ -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 { diff --git a/src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java b/src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java index 1cc8aa2b10..749ed98218 100644 --- a/src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java +++ b/src/examples/src/org/apache/poi/xslf/usermodel/PieChartDemo.java @@ -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)); diff --git a/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java b/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java index 731b732f8d..567d39a102 100644 --- a/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java +++ b/src/examples/src/org/apache/poi/xwpf/usermodel/examples/BarChartExample.java @@ -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); diff --git a/src/examples/src/org/apache/poi/xwpf/usermodel/examples/ChartFromScratch.java b/src/examples/src/org/apache/poi/xwpf/usermodel/examples/ChartFromScratch.java index 4a1a78150f..ee5624fd57 100644 --- a/src/examples/src/org/apache/poi/xwpf/usermodel/examples/ChartFromScratch.java +++ b/src/examples/src/org/apache/poi/xwpf/usermodel/examples/ChartFromScratch.java @@ -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); 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 list = _records.get(Short.valueOf(sid)); + List 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 formatMap = formatCache.get(locale); - if (formatMap == null) { - formatMap = new WeakHashMap<>(); - formatCache.put(locale, formatMap); - } + Map 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 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 toList(CellRangeAddress[] temp) { List 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(); diff --git a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java index fefae87a89..7cee2a0187 100644 --- a/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java +++ b/src/ooxml/java/org/apache/poi/poifs/crypt/dsig/services/RelationshipTransformService.java @@ -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 diff --git a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java index 7903c9c570..ebab4c5f23 100644 --- a/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java +++ b/src/ooxml/java/org/apache/poi/xddf/usermodel/text/XDDFTextRun.java @@ -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]); } /** diff --git a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBSheetHandler.java b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBSheetHandler.java index 726c2eeb89..b726545daf 100644 --- a/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBSheetHandler.java +++ b/src/ooxml/java/org/apache/poi/xssf/binary/XSSFBSheetHandler.java @@ -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); diff --git a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormatting.java b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormatting.java index 671e781c82..eff8e375b4 100644 --- a/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormatting.java +++ b/src/ooxml/java/org/apache/poi/xssf/usermodel/XSSFConditionalFormatting.java @@ -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 diff --git a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java index 884cc8ef11..994deb6daf 100644 --- a/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java +++ b/src/ooxml/java/org/apache/poi/xwpf/usermodel/XWPFDocument.java @@ -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 list = packagePictures.get(picData.getChecksum()); - if (list == null) { - list = new ArrayList<>(1); - packagePictures.put(picData.getChecksum(), list); - } + List list = packagePictures.computeIfAbsent(picData.getChecksum(), k -> new ArrayList<>(1)); if (!list.contains(picData)) { list.add(picData); } diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java index c63a0493a3..56417bce75 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/Chunk.java @@ -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 diff --git a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java index e1ac0e8ad8..b43a0a10e1 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/chunks/ChunkFactory.java @@ -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); diff --git a/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java b/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java index 4c0c890f93..a669a0af52 100644 --- a/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java +++ b/src/scratchpad/src/org/apache/poi/hdgf/streams/ChunkStream.java @@ -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]); } } diff --git a/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java b/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java index 505ad50a2f..47b16b7d4e 100644 --- a/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java +++ b/src/scratchpad/src/org/apache/poi/hpbf/model/EscherPart.java @@ -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() { diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java b/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java index ced5508a9d..1c5fb4c4c4 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/ExObjList.java @@ -50,7 +50,7 @@ public class ExObjList extends RecordContainer { } } - return links.toArray(new ExHyperlink[links.size()]); + return links.toArray(new ExHyperlink[0]); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java b/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java index 4dd0f3f033..8451193c33 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/MainMaster.java @@ -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]); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/Record.java b/src/scratchpad/src/org/apache/poi/hslf/record/Record.java index c4ec8c983f..fb241568fb 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/Record.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/Record.java @@ -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]); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java b/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java index f7cf20107b..546c07691b 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/RecordContainer.java @@ -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; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java b/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java index 0c6e825d9b..268145d31c 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/SlideListWithText.java @@ -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]); } /** diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextProp9Atom.java b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextProp9Atom.java index d11f406fae..cedea7f646 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextProp9Atom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/StyleTextProp9Atom.java @@ -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 +} diff --git a/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java b/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java index 115dc21e4c..d572290657 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java +++ b/src/scratchpad/src/org/apache/poi/hslf/record/TextSpecInfoAtom.java @@ -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 diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java index 63977ccc23..4ab01f0b31 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSlideShowEncrypted.java @@ -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; } diff --git a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSoundData.java b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSoundData.java index 51272e917f..ad0762de7a 100644 --- a/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSoundData.java +++ b/src/scratchpad/src/org/apache/poi/hslf/usermodel/HSLFSoundData.java @@ -89,6 +89,6 @@ public final class HSLFSoundData { } } - return lst.toArray(new HSLFSoundData[lst.size()]); + return lst.toArray(new HSLFSoundData[0]); } } diff --git a/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java b/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java index 15a961ab66..19d73610d7 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/MAPIMessage.java @@ -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 diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java index 9e31294c51..70b5f6233a 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/AttachmentChunks.java @@ -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 diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java index dacf09ed27..c2014a5032 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/Chunks.java @@ -110,7 +110,7 @@ public final class Chunks implements ChunkGroupWithProperties { for (List 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 +} diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/NameIdChunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/NameIdChunks.java index b41bcca83a..71fb2ef7df 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/NameIdChunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/NameIdChunks.java @@ -30,7 +30,7 @@ public final class NameIdChunks implements ChunkGroup { private List allChunks = new ArrayList<>(); public Chunk[] getAll() { - return allChunks.toArray(new Chunk[allChunks.size()]); + return allChunks.toArray(new Chunk[0]); } @Override diff --git a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java index e9241845fd..aa6926ceef 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java @@ -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 diff --git a/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java b/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java index c16f7afae7..980cf0a24b 100644 --- a/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java +++ b/src/scratchpad/src/org/apache/poi/hsmf/parsers/POIFSChunkParser.java @@ -99,7 +99,7 @@ public final class POIFSChunkParser { } // Finish - return groups.toArray(new ChunkGroup[groups.size()]); + return groups.toArray(new ChunkGroup[0]); } /** diff --git a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java index 6792c358f9..6c17397289 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordUtils.java @@ -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++ ) { diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/BookmarksTables.java b/src/scratchpad/src/org/apache/poi/hwpf/model/BookmarksTables.java index 691273f41a..877b3639c8 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/BookmarksTables.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/BookmarksTables.java @@ -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(); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java index 9d62c9c52f..ee6e15051d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/ComplexFileTable.java @@ -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"); diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java index 67a74cea72..19256607a2 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/FSPATable.java @@ -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() diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/OldFontTable.java b/src/scratchpad/src/org/apache/poi/hwpf/model/OldFontTable.java index 28e6a04303..814f0e39f6 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/OldFontTable.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/OldFontTable.java @@ -57,7 +57,7 @@ public final class OldFontTable { startOffset += oldFfn.getLength(); } - _fontNames = ffns.toArray(new OldFfn[ffns.size()]); + _fontNames = ffns.toArray(new OldFfn[0]); } diff --git a/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfCps.java b/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfCps.java index c838a1a21e..54dc1afe52 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfCps.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/model/PlexOfCps.java @@ -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 diff --git a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BookmarksImpl.java b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BookmarksImpl.java index 8a80a743e5..24a7c8ff8d 100644 --- a/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BookmarksImpl.java +++ b/src/scratchpad/src/org/apache/poi/hwpf/usermodel/BookmarksImpl.java @@ -231,12 +231,7 @@ public class BookmarksImpl implements Bookmarks GenericPropertyNode property = bookmarksTables .getDescriptorFirst( b ); Integer positionKey = Integer.valueOf( property.getStart() ); - List atPositionList = result.get( positionKey ); - if ( atPositionList == null ) - { - atPositionList = new LinkedList<>(); - result.put( positionKey, atPositionList ); - } + List atPositionList = result.computeIfAbsent(positionKey, k -> new LinkedList<>()); atPositionList.add( property ); } diff --git a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java index 30c177f086..ba49c8cb5f 100644 --- a/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java +++ b/src/scratchpad/testcases/org/apache/poi/hslf/record/TestTxMasterStyleAtom.java @@ -235,6 +235,6 @@ public final class TestTxMasterStyleAtom extends TestCase { } } - return lst.toArray(new TxMasterStyleAtom[lst.size()]); + return lst.toArray(new TxMasterStyleAtom[0]); } } diff --git a/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java b/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java index 305bc5f026..5ce8df3cd0 100644 --- a/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java +++ b/src/testcases/org/apache/poi/hssf/record/aggregates/TestColumnInfoRecordsAggregate.java @@ -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]); } } diff --git a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java index 0ca0304381..aec1f20d6e 100644 --- a/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java +++ b/src/testcases/org/apache/poi/poifs/filesystem/TestPOIFSDocumentPath.java @@ -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()); -- 2.39.5