From f2d37da8fc4ca456d0794c3a97144b461378917a Mon Sep 17 00:00:00 2001 From: PJ Fanning Date: Mon, 17 Jan 2022 00:58:27 +0000 Subject: [PATCH] remove use of deprecated commons-math methods git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1897138 13f79535-47bb-0310-9956-ffa450edef68 --- .../org/apache/poi/hslf/record/MasterTextPropAtom.java | 3 +-- .../org/apache/poi/poifs/filesystem/POIFSFileSystem.java | 5 ++--- .../java/org/apache/poi/poifs/property/RootProperty.java | 3 +-- .../java/org/apache/poi/ss/util/cellwalk/CellWalk.java | 8 ++------ 4 files changed, 6 insertions(+), 13 deletions(-) diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/MasterTextPropAtom.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/MasterTextPropAtom.java index 1b96b35260..a6065e3e24 100644 --- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/MasterTextPropAtom.java +++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/record/MasterTextPropAtom.java @@ -26,7 +26,6 @@ import java.util.List; import java.util.Map; import java.util.function.Supplier; -import org.apache.commons.math3.util.ArithmeticUtils; import org.apache.poi.hslf.model.textproperties.IndentProp; import org.apache.poi.util.GenericRecordUtil; import org.apache.poi.util.IOUtils; @@ -132,7 +131,7 @@ public final class MasterTextPropAtom extends RecordAtom { */ private void write() { int pos = 0; - long newSize = ArithmeticUtils.mulAndCheck((long)indents.size(), (long)6); + long newSize = Math.multiplyExact((long)indents.size(), (long)6); _data = IOUtils.safelyAllocate(newSize, MAX_RECORD_LENGTH); for (IndentProp prop : indents) { LittleEndian.putInt(_data, pos, prop.getCharactersCovered()); diff --git a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java index b9e85c08c0..222752eb78 100644 --- a/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java +++ b/poi/src/main/java/org/apache/poi/poifs/filesystem/POIFSFileSystem.java @@ -33,7 +33,6 @@ import java.util.Iterator; import java.util.List; import org.apache.commons.io.output.UnsynchronizedByteArrayOutputStream; -import org.apache.commons.math3.util.ArithmeticUtils; import org.apache.logging.log4j.LogManager; import org.apache.logging.log4j.Logger; import org.apache.poi.EmptyFileException; @@ -127,7 +126,7 @@ public class POIFSFileSystem extends BlockStore protected void createNewDataSource() { // Data needs to initially hold just the header block, // a single bat block, and an empty properties section - long blockSize = ArithmeticUtils.mulAndCheck(bigBlockSize.getBigBlockSize(), 3L); + long blockSize = Math.multiplyExact(bigBlockSize.getBigBlockSize(), 3L); _data = new ByteArrayBackedDataSource(IOUtils.safelyAllocate(blockSize, MAX_RECORD_LENGTH)); } @@ -455,7 +454,7 @@ public class POIFSFileSystem extends BlockStore // Ensure there's a spot in the file for it ByteBuffer buffer = ByteBuffer.allocate(bigBlockSize.getBigBlockSize()); // Header isn't in BATs - long writeTo = ArithmeticUtils.mulAndCheck(1L + offset, bigBlockSize.getBigBlockSize()); + long writeTo = Math.multiplyExact(1L + offset, (long)bigBlockSize.getBigBlockSize()); _data.write(buffer, writeTo); // All done return newBAT; diff --git a/poi/src/main/java/org/apache/poi/poifs/property/RootProperty.java b/poi/src/main/java/org/apache/poi/poifs/property/RootProperty.java index c74a02a29d..8b5faaa4fd 100644 --- a/poi/src/main/java/org/apache/poi/poifs/property/RootProperty.java +++ b/poi/src/main/java/org/apache/poi/poifs/property/RootProperty.java @@ -17,7 +17,6 @@ package org.apache.poi.poifs.property; -import org.apache.commons.math3.util.ArithmeticUtils; import org.apache.poi.poifs.common.POIFSConstants; /** @@ -56,7 +55,7 @@ public final class RootProperty extends DirectoryProperty { { final int BLOCK_SHIFT = 6; final int _block_size = 1 << BLOCK_SHIFT; - super.setSize(ArithmeticUtils.mulAndCheck(size, _block_size)); + super.setSize(Math.multiplyExact(size, _block_size)); } /** diff --git a/poi/src/main/java/org/apache/poi/ss/util/cellwalk/CellWalk.java b/poi/src/main/java/org/apache/poi/ss/util/cellwalk/CellWalk.java index 480bcf5dd4..25e567f3ca 100644 --- a/poi/src/main/java/org/apache/poi/ss/util/cellwalk/CellWalk.java +++ b/poi/src/main/java/org/apache/poi/ss/util/cellwalk/CellWalk.java @@ -17,10 +17,6 @@ package org.apache.poi.ss.util.cellwalk; -import static org.apache.commons.math3.util.ArithmeticUtils.addAndCheck; -import static org.apache.commons.math3.util.ArithmeticUtils.mulAndCheck; -import static org.apache.commons.math3.util.ArithmeticUtils.subAndCheck; - import org.apache.poi.ss.usermodel.Cell; import org.apache.poi.ss.usermodel.CellType; import org.apache.poi.ss.usermodel.Row; @@ -93,9 +89,9 @@ public class CellWalk { continue; } - long rowSize = mulAndCheck(subAndCheck(ctx.rowNumber, firstRow), (long)width); + long rowSize = Math.multiplyExact(Math.subtractExact(ctx.rowNumber, firstRow), (long)width); - ctx.ordinalNumber = addAndCheck(rowSize, (ctx.colNumber - firstColumn + 1)); + ctx.ordinalNumber = Math.addExact(rowSize, (ctx.colNumber - firstColumn + 1)); handler.onCell(currentCell, ctx); } -- 2.39.5