try to avoid casting to int

git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1866933 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
PJ Fanning 2019-09-14 09:54:11 +00:00
parent 8a9af96f95
commit dc6a4a99e2
29 changed files with 74 additions and 73 deletions

View File

@ -182,7 +182,7 @@ public class SVSheetTable extends JTable {
Row row = sheet.getRow(i - sheet.getFirstRowNum());
if (row != null) {
short h = row.getHeight();
int height = (int)Math.round(Math.max(1., h / (res / 70. * 20.) + 3.));
int height = Math.toIntExact(Math.round(Math.max(1., h / (res / 70. * 20.) + 3.)));
System.out.printf("%d: %d (%d @ %d)%n", i, height, h, res);
setRowHeight(i, height);
}

View File

@ -703,7 +703,7 @@ public class ToCSV {
if (converted) {
System.out.println("Conversion took " +
(int)((System.currentTimeMillis() - startTime)/1000) + " seconds");
((System.currentTimeMillis() - startTime)/1000) + " seconds");
}
}

View File

@ -399,7 +399,7 @@ public class ToHtml {
* @return the approximate number of pixels for a typical display
*/
protected int widthToPixels(final double widthUnits) {
return (int) (Math.round(widthUnits * 9 / 256));
return Math.toIntExact(Math.round(widthUnits * 9 / 256));
}
private void printCols(Map<Integer, Integer> widths) {

View File

@ -182,10 +182,10 @@ public class Section {
final TreeBidiMap<Long,Long> offset2Id = new TreeBidiMap<>();
for (int i = 0; i < propertyCount; i++) {
/* Read the property ID. */
long id = (int)leis.readUInt();
long id = leis.readUInt();
/* Offset from the section's start. */
long off = (int)leis.readUInt();
long off = leis.readUInt();
offset2Id.put(off, id);
}
@ -196,7 +196,7 @@ public class Section {
int codepage = -1;
if (cpOffset != null) {
/* Read the property's value type. It must be VT_I2. */
leis.setReadIndex((int)(this._offset + cpOffset));
leis.setReadIndex(Math.toIntExact(this._offset + cpOffset));
final long type = leis.readUInt();
if (type != Variant.VT_I2) {
@ -221,7 +221,7 @@ public class Section {
}
int pLen = propLen(offset2Id, off, size);
leis.setReadIndex((int)(this._offset + off));
leis.setReadIndex(Math.toIntExact(this._offset + off));
if (id == PropertyIDMap.PID_DICTIONARY) {
leis.mark(100000);
@ -242,7 +242,7 @@ public class Section {
}
}
sectionBytes.write(src, (int)_offset, size);
sectionBytes.write(src, Math.toIntExact(_offset), size);
padSectionBytes();
}
@ -261,7 +261,7 @@ public class Section {
Long nextKey = offset2Id.nextKey(entryOffset);
long begin = entryOffset;
long end = (nextKey != null) ? nextKey : maxSize;
return (int)(end - begin);
return Math.toIntExact(end - begin);
}
@ -823,7 +823,7 @@ public class Section {
/* Read the string - Strip 0x00 characters from the end of the string. */
int cp = (codepage == -1) ? Property.DEFAULT_CODEPAGE : codepage;
int nrBytes = (int)((sLength-1) * (cp == CodePageUtil.CP_UNICODE ? 2 : 1));
int nrBytes = Math.toIntExact(((sLength-1) * (cp == CodePageUtil.CP_UNICODE ? 2 : 1)));
if (nrBytes > 0xFFFFFF) {
LOG.log(POILogger.WARN, errMsg);
isCorrupted = true;
@ -946,7 +946,7 @@ public class Section {
for (Property aPa : pa) {
hashCode += aPa.hashCode();
}
return (int) (hashCode & 0x0ffffffffL);
return Math.toIntExact(hashCode & 0x0ffffffffL);
}

View File

@ -62,6 +62,6 @@ final class ParityFunction implements FreeRefFunction {
d = -d;
}
long v = (long) Math.floor(d);
return (int) (v & 0x0001);
return Math.toIntExact(v & 0x0001);
}
}

View File

@ -354,7 +354,7 @@ public class CellReference {
if(rowNum > Integer.MAX_VALUE) {
return false;
}
return isRowWithinRange((int)rowNum, ssVersion);
return isRowWithinRange(Math.toIntExact(rowNum), ssVersion);
}
/**

View File

@ -54,7 +54,7 @@ final class ExpandedDouble {
private final int _binaryExponent;
public ExpandedDouble(long rawBits) {
int biasedExp = (int) (rawBits >> 52);
int biasedExp = Math.toIntExact(rawBits >> 52);
if (biasedExp == 0) {
// sub-normal numbers
BigInteger frac = BigInteger.valueOf(rawBits).and(BI_FRAC_MASK);

View File

@ -39,6 +39,6 @@ final class IEEEDouble {
* @return the top 12 bits (sign and biased exponent value)
*/
public static int getBiasedExponent(long rawBits) {
return (int) ((rawBits & EXPONENT_MASK) >> EXPONENT_SHIFT);
return Math.toIntExact((rawBits & EXPONENT_MASK) >> EXPONENT_SHIFT);
}
}

View File

@ -401,7 +401,7 @@ public class HexDump {
char[] buf = new char[nDigits];
long acc = value;
for(int i=nDigits-1; i>=0; i--) {
int digit = (int)(acc & 0x0F);
int digit = Math.toIntExact(acc & 0x0F);
buf[i] = (char) (digit < 10 ? ('0' + digit) : ('A' + digit - 10));
acc >>>= 4;
}

View File

@ -16,9 +16,6 @@
==================================================================== */
package org.apache.poi.openxml4j.util;
import static org.apache.commons.collections4.IteratorUtils.asIterable;
import static org.apache.commons.collections4.IteratorUtils.asIterator;
import java.io.IOException;
import java.io.InputStream;
import java.util.Enumeration;
@ -76,7 +73,9 @@ public class ZipFileZipEntrySource implements ZipEntrySource {
}
// the opc spec allows case-insensitive filename matching (see #49609)
for (final ZipArchiveEntry ze : asIterable(asIterator(zipArchive.getEntries()))) {
final Enumeration<ZipArchiveEntry> zipArchiveEntryEnumeration = zipArchive.getEntries();
while (zipArchiveEntryEnumeration.hasMoreElements()) {
ZipArchiveEntry ze = zipArchiveEntryEnumeration.nextElement();
if (normalizedPath.equalsIgnoreCase(ze.getName().replace('\\','/'))) {
return ze;
}

View File

@ -18,11 +18,11 @@ package org.apache.poi.openxml4j.util;
import java.io.IOException;
import java.io.InputStream;
import java.util.Collections;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Map;
import org.apache.commons.collections4.IteratorUtils;
import org.apache.commons.compress.archivers.zip.ZipArchiveEntry;
/**
@ -58,7 +58,7 @@ public class ZipInputStreamZipEntrySource implements ZipEntrySource {
@Override
public Enumeration<? extends ZipArchiveEntry> getEntries() {
return IteratorUtils.asEnumeration(zipEntries.values().iterator());
return Collections.enumeration(zipEntries.values());
}
@Override

View File

@ -27,7 +27,7 @@ public class Angles {
public static final int OOXML_DEGREE = 60_000;
public static final int degreesToAttribute(double angle) {
return (int) (OOXML_DEGREE * angle);
return Math.toIntExact(Math.round(OOXML_DEGREE * angle));
}
public static final double attributeToDegrees(int angle) {

View File

@ -47,6 +47,6 @@ public class XDDFBulletSizePercent implements XDDFBulletSize {
}
public void setPercent(double value) {
percent.setVal((int) (1000 * value));
percent.setVal(Math.toIntExact(Math.round(1000 * value)));
}
}

View File

@ -45,6 +45,6 @@ public class XDDFBulletSizePoints implements XDDFBulletSize {
}
public void setPoints(double value) {
points.setVal((int) (100 * value));
points.setVal(Math.toIntExact(Math.round(100 * value)));
}
}

View File

@ -142,7 +142,7 @@ public class XDDFRunProperties {
} else if (size < 1 || 400 < size) {
throw new IllegalArgumentException("Minimum inclusive = 1. Maximum inclusive = 400.");
} else {
props.setSz((int) (100 * size));
props.setSz((int)(100 * size));
}
}

View File

@ -542,8 +542,7 @@ public class XMLSlideShow extends POIXMLDocument
*/
@Override
public XSLFPictureData addPicture(File pict, PictureType format) throws IOException {
int length = (int) pict.length();
byte[] data = IOUtils.safelyAllocate(length, MAX_RECORD_LENGTH);
byte[] data = IOUtils.safelyAllocate(pict.length(), MAX_RECORD_LENGTH);
try (InputStream is = new FileInputStream(pict)) {
IOUtils.readFully(is, data);
}

View File

@ -577,10 +577,10 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
// value of 0 or 1000 indicates no background,
// values 1-999 refer to the index of a fill style within the fillStyleLst element
// values 1001 and above refer to the index of a background fill style within the bgFillStyleLst element.
int idx = (int)fillRef.getIdx();
long idx = fillRef.getIdx();
CTStyleMatrix matrix = theme.getXmlObject().getThemeElements().getFmtScheme();
final XmlObject styleLst;
int childIdx;
long childIdx;
if (idx >= 1 && idx <= 999) {
childIdx = idx-1;
styleLst = (isLineStyle) ? matrix.getLnStyleLst() : matrix.getFillStyleLst();
@ -592,7 +592,7 @@ public abstract class XSLFShape implements Shape<XSLFShape,XSLFTextParagraph> {
}
XmlCursor cur = styleLst.newCursor();
XSLFFillProperties fp = null;
if (cur.toChild(childIdx)) {
if (cur.toChild(Math.toIntExact(childIdx))) {
fp = XSLFPropertiesDelegate.getFillDelegate(cur.getObject());
}
cur.dispose();

View File

@ -78,7 +78,6 @@ import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndType;
import org.openxmlformats.schemas.drawingml.x2006.main.STLineEndWidth;
import org.openxmlformats.schemas.drawingml.x2006.main.STPresetLineDashVal;
import org.openxmlformats.schemas.drawingml.x2006.main.STShapeType;
import org.openxmlformats.schemas.presentationml.x2006.main.CTPlaceholder;
/**
* Represents a single (non-group) shape in a .pptx slide show
@ -242,7 +241,7 @@ public abstract class XSLFSimpleShape extends XSLFShape
return null;
}
// 1-based index of a line style within the style matrix
int idx = (int)lnRef.getIdx();
int idx = Math.toIntExact(lnRef.getIdx());
XSLFTheme theme = getSheet().getTheme();
if (theme == null) {
@ -359,7 +358,7 @@ public abstract class XSLFSimpleShape extends XSLFShape
if (lnRef == null) {
return null;
}
int idx = (int)lnRef.getIdx();
int idx = Math.toIntExact(lnRef.getIdx());
CTSchemeColor phClr = lnRef.getSchemeClr();
if(idx <= 0){
return null;

View File

@ -216,8 +216,8 @@ public class PPTX2PNG {
break;
}
final int width = (int) Math.rint(pgsize.getWidth() * scale / lenSide);
final int height = (int) Math.rint(pgsize.getHeight() * scale / lenSide);
final int width = Math.toIntExact(Math.round(pgsize.getWidth() * scale / lenSide));
final int height = Math.toIntExact(Math.round(pgsize.getHeight() * scale / lenSide));
for (int slideNo : slidenum) {

View File

@ -119,7 +119,7 @@ public class CommentsTable extends POIXMLDocumentPart implements Comments {
@Override
public String getAuthor(long authorId) {
return comments.getAuthors().getAuthorArray((int)authorId);
return comments.getAuthors().getAuthorArray(Math.toIntExact(authorId));
}
@Override

View File

@ -281,7 +281,7 @@ import org.apache.poi.util.Internal;
}
}
final double width = maxColumnWidths.get(column).getMaxColumnWidth(useMergedCells);
return (int) (256*width);
return Math.toIntExact(Math.round(256*width));
}

View File

@ -85,7 +85,7 @@ class OpcOutputStream extends DeflaterOutputStream {
}
current.size = def.getBytesRead();
current.compressedSize = (int) def.getBytesWritten();
current.compressedSize = Math.toIntExact(def.getBytesWritten());
current.crc = crc.getValue();
written += current.compressedSize;

View File

@ -465,7 +465,8 @@ public final class XSSFCell extends CellBase {
if (f == null) {
return null;
} else if (f.getT() == STCellFormulaType.SHARED) {
return convertSharedFormula((int)f.getSi(), fpb == null ? XSSFEvaluationWorkbook.create(getSheet().getWorkbook()) : fpb);
return convertSharedFormula(Math.toIntExact(f.getSi()),
fpb == null ? XSSFEvaluationWorkbook.create(getSheet().getWorkbook()) : fpb);
} else {
return f.getStringValue();
}
@ -614,7 +615,7 @@ public final class XSSFCell extends CellBase {
XSSFCellStyle style = null;
if(_stylesSource.getNumCellStyles() > 0){
long idx = _cell.isSetS() ? _cell.getS() : 0;
style = _stylesSource.getStyleAt((int)idx);
style = _stylesSource.getStyleAt(Math.toIntExact(idx));
}
return style;
}
@ -1224,7 +1225,7 @@ public final class XSSFCell extends CellBase {
}
CalculationChain calcChain = getSheet().getWorkbook().getCalculationChain();
int sheetId = (int)getSheet().sheet.getSheetId();
int sheetId = Math.toIntExact(getSheet().sheet.getSheetId());
//remove the reference in the calculation chain
if(calcChain != null) calcChain.removeItem(sheetId, getReference());

View File

@ -236,7 +236,7 @@ public class XSSFCellStyle implements CellStyle {
public BorderStyle getBorderBottom() {
if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId();
int idx = Math.toIntExact(_cellXf.getBorderId());
CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder();
STBorderStyle.Enum ptrn = ct.isSetBottom() ? ct.getBottom().getStyle() : null;
if (ptrn == null) {
@ -254,7 +254,7 @@ public class XSSFCellStyle implements CellStyle {
public BorderStyle getBorderLeft() {
if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId();
int idx = Math.toIntExact(_cellXf.getBorderId());
CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder();
STBorderStyle.Enum ptrn = ct.isSetLeft() ? ct.getLeft().getStyle() : null;
if (ptrn == null) {
@ -270,7 +270,7 @@ public class XSSFCellStyle implements CellStyle {
public BorderStyle getBorderRight() {
if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId();
int idx = Math.toIntExact(_cellXf.getBorderId());
CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder();
STBorderStyle.Enum ptrn = ct.isSetRight() ? ct.getRight().getStyle() : null;
if (ptrn == null) {
@ -288,7 +288,7 @@ public class XSSFCellStyle implements CellStyle {
public BorderStyle getBorderTop() {
if(!_cellXf.getApplyBorder()) return BorderStyle.NONE;
int idx = (int)_cellXf.getBorderId();
int idx = Math.toIntExact(_cellXf.getBorderId());
CTBorder ct = _stylesSource.getBorderAt(idx).getCTBorder();
STBorderStyle.Enum ptrn = ct.isSetTop() ? ct.getTop().getStyle() : null;
if (ptrn == null) {
@ -323,7 +323,7 @@ public class XSSFCellStyle implements CellStyle {
public XSSFColor getBottomBorderXSSFColor() {
if(!_cellXf.getApplyBorder()) return null;
int idx = (int)_cellXf.getBorderId();
int idx = Math.toIntExact(_cellXf.getBorderId());
XSSFCellBorder border = _stylesSource.getBorderAt(idx);
return border.getBorderColor(BorderSide.BOTTOM);
@ -549,7 +549,7 @@ public class XSSFCellStyle implements CellStyle {
public XSSFColor getLeftBorderXSSFColor() {
if(!_cellXf.getApplyBorder()) return null;
int idx = (int)_cellXf.getBorderId();
int idx = Math.toIntExact(_cellXf.getBorderId());
XSSFCellBorder border = _stylesSource.getBorderAt(idx);
return border.getBorderColor(BorderSide.LEFT);
@ -592,7 +592,7 @@ public class XSSFCellStyle implements CellStyle {
public XSSFColor getRightBorderXSSFColor() {
if(!_cellXf.getApplyBorder()) return null;
int idx = (int)_cellXf.getBorderId();
int idx = Math.toIntExact(_cellXf.getBorderId());
XSSFCellBorder border = _stylesSource.getBorderAt(idx);
return border.getBorderColor(BorderSide.RIGHT);
@ -644,7 +644,7 @@ public class XSSFCellStyle implements CellStyle {
public XSSFColor getTopBorderXSSFColor() {
if(!_cellXf.getApplyBorder()) return null;
int idx = (int)_cellXf.getBorderId();
int idx = Math.toIntExact(_cellXf.getBorderId());
XSSFCellBorder border = _stylesSource.getBorderAt(idx);
return border.getBorderColor(BorderSide.TOP);
@ -960,7 +960,7 @@ public class XSSFCellStyle implements CellStyle {
private CTBorder getCTBorder(){
CTBorder ct;
if(_cellXf.getApplyBorder()) {
int idx = (int)_cellXf.getBorderId();
int idx = Math.toIntExact(_cellXf.getBorderId());
XSSFCellBorder cf = _stylesSource.getBorderAt(idx);
ct = (CTBorder)cf.getCTBorder().copy();

View File

@ -256,7 +256,7 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
}
public int getDx1() {
return (int) getCell1().getColOff();
return Math.toIntExact(getCell1().getColOff());
}
/**
@ -268,7 +268,7 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
}
public int getDy1() {
return (int) getCell1().getRowOff();
return Math.toIntExact(getCell1().getRowOff());
}
/**
@ -280,7 +280,7 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
}
public int getDy2() {
return (int) getCell2().getRowOff();
return Math.toIntExact(getCell2().getRowOff());
}
/**
@ -292,7 +292,7 @@ public class XSSFClientAnchor extends XSSFAnchor implements ClientAnchor {
}
public int getDx2() {
return (int) getCell2().getColOff();
return Math.toIntExact(getCell2().getColOff());
}
/**

View File

@ -407,7 +407,7 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
*/
@Override
public int getRowNum() {
return (int) (_row.getR() - 1);
return Math.toIntExact(_row.getR() - 1);
}
/**
@ -469,7 +469,7 @@ public class XSSFRow implements Row, Comparable<XSSFRow> {
StylesTable stylesSource = getSheet().getWorkbook().getStylesSource();
if(stylesSource.getNumCellStyles() > 0) {
return stylesSource.getStyleAt((int)_row.getS());
return stylesSource.getStyleAt(Math.toIntExact(_row.getS()));
} else {
return null;
}

View File

@ -559,7 +559,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
if (width > maxColumnWidth) {
width = maxColumnWidth;
}
setColumnWidth(column, (int)(width));
setColumnWidth(column, Math.toIntExact(Math.round(width)));
columnHelper.setColBestFit(column, true);
}
}
@ -900,7 +900,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
CTBreak[] brkArray = ctPageBreak.getBrkArray();
int[] breaks = new int[brkArray.length];
for (int i = 0 ; i < brkArray.length ; i++) {
breaks[i] = (int) brkArray[i].getId() - 1;
breaks[i] = Math.toIntExact(brkArray[i].getId() - 1);
}
return breaks;
}
@ -944,7 +944,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
public int getColumnWidth(int columnIndex) {
CTCol col = columnHelper.getColumn(columnIndex, false);
double width = col == null || !col.isSetWidth() ? getDefaultColumnWidth() : col.getWidth();
return (int)(width*256);
return Math.toIntExact(Math.round(width*256));
}
/**
@ -973,7 +973,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
@Override
public int getDefaultColumnWidth() {
CTSheetFormatPr pr = worksheet.getSheetFormatPr();
return pr == null ? 8 : (int)pr.getBaseColWidth();
return pr == null ? 8 : Math.toIntExact(pr.getBaseColWidth());
}
/**
@ -1686,7 +1686,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
//col must exist
short outlineLevel=col.getOutlineLevel();
col.setOutlineLevel((short)(outlineLevel+1));
index=(int)col.getMax();
index = Math.toIntExact(col.getMax());
}
worksheet.setColsArray(0,ctCols);
setSheetFormatPrOutlineLevelCol();
@ -2256,7 +2256,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
// split to 3 records
CTCol ciMid = columnHelper.cloneCol(cols, ci);
CTCol ciEnd = columnHelper.cloneCol(cols, ci);
int lastcolumn = (int) ciMax;
int lastcolumn = Math.toIntExact(ciMax);
ci.setMax(targetColumnIx - 1);
@ -2308,7 +2308,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
}
idx++;
}
return (int) columnInfo.getMax();
return Math.toIntExact(columnInfo.getMax());
}
private boolean isAdjacentBefore(CTCol col, CTCol otherCol) {
@ -2363,7 +2363,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
CTCol col = columnHelper.getColumn(columnIndex, false);
int colInfoIx = columnHelper.getIndexOfColumn(cols, col);
int idx = findColInfoIdx((int) col.getMax(), colInfoIx);
int idx = findColInfoIdx(Math.toIntExact(col.getMax()), colInfoIx);
if (idx == -1) {
return;
}
@ -2408,7 +2408,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
}
// Write collapse flag (stored in a single col info record after this
// outline group)
setColumn((int) columnInfo.getMax() + 1, null, null,
setColumn(Math.toIntExact(columnInfo.getMax() + 1), null, null,
Boolean.FALSE, Boolean.FALSE);
}
@ -3286,7 +3286,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
if (col != null) {
short outlineLevel = col.getOutlineLevel();
col.setOutlineLevel((short) (outlineLevel - 1));
index = (int) col.getMax();
index = Math.toIntExact(col.getMax());
if (col.getOutlineLevel() <= 0) {
int colIndex = columnHelper.getIndexOfColumn(cols, col);
@ -3492,7 +3492,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
// the sheet has (i.e. sheet 1 -> comments 1)
try {
sheetComments = (CommentsTable)createRelationship(
XSSFRelation.SHEET_COMMENTS, XSSFFactory.getInstance(), (int)sheet.getSheetId());
XSSFRelation.SHEET_COMMENTS, XSSFFactory.getInstance(), Math.toIntExact(sheet.getSheetId()));
} catch(PartAlreadyExistsException e) {
// Technically a sheet doesn't need the same number as
// it's comments, and clearly someone has already pinched
@ -3563,7 +3563,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
sf.setRef(effectiveRef);
}
sharedFormulas.put((int)f.getSi(), sf);
sharedFormulas.put(Math.toIntExact(f.getSi()), sf);
}
if (f != null && f.getT() == STCellFormulaType.ARRAY && f.getRef() != null) {
arrayFormulas.add(CellRangeAddress.valueOf(f.getRef()));
@ -4649,7 +4649,7 @@ public class XSSFSheet extends POIXMLDocumentPart implements Sheet {
nextCell.getColumnIndex(), ref.getLastColumn());
nextF.setRef(nextRef.formatAsString());
sharedFormulas.put((int)nextF.getSi(), nextF);
sharedFormulas.put(Math.toIntExact(nextF.getSi()), nextF);
break DONE;
}
}

View File

@ -109,7 +109,7 @@ import java.util.List;
if (shiftedFormula != null) {
f.setStringValue(shiftedFormula);
if(f.getT() == STCellFormulaType.SHARED){
int si = (int)f.getSi();
int si = Math.toIntExact(f.getSi());
CTCellFormula sf = sheet.getSharedFormula(si);
sf.setStringValue(shiftedFormula);
updateRefInCTCellFormula(row, formulaShifter, sf);

View File

@ -20,9 +20,10 @@ package org.apache.poi.ss.util;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertArrayEquals;
import java.util.Iterator;
import java.util.Set;
import java.util.HashSet;
import org.apache.commons.collections4.IteratorUtils;
/**
* Tests CellRangeUtil.
@ -76,7 +77,9 @@ public final class TestCellRangeUtil {
private static Set<CellAddress> getCellAddresses(CellRangeAddress[] ranges) {
final Set<CellAddress> set = new HashSet<>();
for (final CellRangeAddress range : ranges) {
set.addAll(IteratorUtils.toList(range.iterator()));
for (Iterator<CellAddress> iter = range.iterator(); iter.hasNext(); ) {
set.add(iter.next());
}
}
return set;
}