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);
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 {
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));
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);
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);
* @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]);
}
/**
}
values.add(value);
}
- _values = values.toArray(new TypedPropertyValue[values.size()]);
+ _values = values.toArray(new TypedPropertyValue[0]);
}
public TypedPropertyValue[] getValues(){
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;
// 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);
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
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() {
* 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);
}
in.nextRecord();
}
}
- _sstInfos = lst.toArray(new InfoSubRecord[lst.size()]);
+ _sstInfos = lst.toArray(new InfoSubRecord[0]);
}
public void setNumStringsPerBucket(short numStrings) {
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;
}
}
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);
package org.apache.poi.hssf.record;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
import org.apache.poi.util.LittleEndianOutput;
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) {
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 {
endIndex = _rowRecords.size()-1;
if (_rowRecordValues == null){
- _rowRecordValues = _rowRecords.values().toArray(new RowRecord[_rowRecords.size()]);
+ _rowRecordValues = _rowRecords.values().toArray(new RowRecord[0]);
}
try {
}
}
- return charts.toArray( new HSSFChart[charts.size()] );
+ return charts.toArray(new HSSFChart[0]);
}
/** Get the X offset of the chart */
* Returns the series of the chart
*/
public HSSFSeries[] getSeries() {
- return series.toArray(new HSSFSeries[series.size()]);
+ return series.toArray(new HSSFSeries[0]);
}
/**
}
}
- linkedDataRecord.setFormulaOfLink(ptgList.toArray(new Ptg[ptgList.size()]));
+ linkedDataRecord.setFormulaOfLink(ptgList.toArray(new Ptg[0]));
return rowCount * colCount;
}
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++)
* @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("@"))
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) {
package org.apache.poi.ss.formula;
+import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Set;
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];
}
}
}
-}
\ No newline at end of file
+}
}
}
- return innerFunc.evaluate(list.toArray(new ValueEval[list.size()]), srcRowIndex, srcColumnIndex);
+ return innerFunc.evaluate(list.toArray(new ValueEval[0]), srcRowIndex, srcColumnIndex);
}
}
}
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;
}
package org.apache.poi.ss.util;
import java.util.ArrayList;
+import java.util.Collections;
import java.util.List;
/**
}
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;
}
}
}
}
- 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();
throw new InvalidAlgorithmParameterException();
}
RelationshipTransformParameterSpec relParams = (RelationshipTransformParameterSpec) params;
- for (String sourceId : relParams.sourceIds) {
- this.sourceIds.add(sourceId);
- }
+ this.sourceIds.addAll(relParams.sourceIds);
}
@Override
.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]);
}
/**
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);
lst.add(CellRangeAddress.valueOf(region));
}
}
- return lst.toArray(new CellRangeAddress[lst.size()]);
+ return lst.toArray(new CellRangeAddress[0]);
}
@Override
}
public XWPFHyperlink[] getHyperlinks() {
- return hyperlinks.toArray(new XWPFHyperlink[hyperlinks.size()]);
+ return hyperlinks.toArray(new XWPFHyperlink[0]);
}
public XWPFComment getCommentByID(String id) {
}
public XWPFComment[] getComments() {
- return comments.toArray(new XWPFComment[comments.size()]);
+ return comments.toArray(new XWPFComment[0]);
}
/**
}
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);
}
// 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
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);
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]);
}
}
ec.add(er);
}
- records = ec.toArray(new EscherRecord[ec.size()]);
+ records = ec.toArray(new EscherRecord[0]);
}
public EscherRecord[] getEscherRecords() {
}
}
- return links.toArray(new ExHyperlink[links.size()]);
+ return links.toArray(new ExHyperlink[0]);
}
/**
}
}
- 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]);
}
/**
}
// Turn the vector into an array, and return
- return children.toArray( new Record[children.size()] );
+ return children.toArray(new Record[0]);
}
/**
rm = r;
}
}
- _children = lst.toArray(new Record[lst.size()]);
+ _children = lst.toArray(new Record[0]);
return rm;
}
}
// Turn the list into an array
- slideAtomsSets = sets.toArray( new SlideAtomsSet[sets.size()] );
+ slideAtomsSets = sets.toArray(new SlideAtomsSet[0]);
}
/**
break;
}
}
- this.autoNumberSchemes = schemes.toArray(new TextPFException9[schemes.size()]);
+ this.autoNumberSchemes = schemes.toArray(new TextPFException9[0]);
}
/**
"autoNumberSchemes", this::getAutoNumberTypes
);
}
-}
\ No newline at end of file
+}
while (bis.getReadIndex() < _data.length) {
lst.add(new TextSpecInfoRun(bis));
}
- return lst.toArray(new TextSpecInfoRun[lst.size()]);
+ return lst.toArray(new TextSpecInfoRun[0]);
}
@Override
recordMap.remove(oldOffset);
}
- return recordMap.values().toArray(new Record[recordMap.size()]);
+ return recordMap.values().toArray(new Record[0]);
}
uea.setMaxPersistWritten(maxSlideId);
- records = recordList.toArray(new Record[recordList.size()]);
+ records = recordList.toArray(new Record[0]);
return records;
}
}
}
- return lst.toArray(new HSLFSoundData[lst.size()]);
+ return lst.toArray(new HSLFSoundData[0]);
}
}
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
}
public Chunk[] getAll() {
- return allChunks.toArray(new Chunk[allChunks.size()]);
+ return allChunks.toArray(new Chunk[0]);
}
@Override
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() {
}
// 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);
}
"Message didn't contain a root list of properties!");
}
}
-}
\ No newline at end of file
+}
private List<Chunk> allChunks = new ArrayList<>();
public Chunk[] getAll() {
- return allChunks.toArray(new Chunk[allChunks.size()]);
+ return allChunks.toArray(new Chunk[0]);
}
@Override
}
public Chunk[] getAll() {
- return allChunks.toArray(new Chunk[allChunks.size()]);
+ return allChunks.toArray(new Chunk[0]);
}
@Override
}
// Finish
- return groups.toArray(new ChunkGroup[groups.size()]);
+ return groups.toArray(new ChunkGroup[0]);
}
/**
}
}
- 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++ )
{
}
int start = tableStream.size();
- SttbUtils.writeSttbfBkmk( names.toArray( new String[names.size()] ),
+ SttbUtils.writeSttbfBkmk( names.toArray(new String[0]),
tableStream );
int end = tableStream.size();
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");
{
result.add( new FSPA( propertyNode.getBytes(), 0 ) );
}
- return result.toArray( new FSPA[result.size()] );
+ return result.toArray(new FSPA[0]);
}
public String toString()
startOffset += oldFfn.getLength();
}
- _fontNames = ffns.toArray(new OldFfn[ffns.size()]);
+ _fontNames = ffns.toArray(new OldFfn[0]);
}
if (_props == null || _props.isEmpty())
return new GenericPropertyNode[0];
- return _props.toArray(new GenericPropertyNode[_props.size()]);
+ return _props.toArray(new GenericPropertyNode[0]);
}
@Override
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 );
}
}
}
- return lst.toArray(new TxMasterStyleAtom[lst.size()]);
+ return lst.toArray(new TxMasterStyleAtom[0]);
}
}
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]);
}
}
{
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());
{
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 =
{
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());