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/scratchpad | |
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/scratchpad')
27 files changed, 33 insertions, 40 deletions
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<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 +} 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<Chunk> 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<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 ); } 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]); } } |