aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPJ Fanning <fanningpj@apache.org>2022-08-06 20:51:57 +0000
committerPJ Fanning <fanningpj@apache.org>2022-08-06 20:51:57 +0000
commit3247a4160e9ba6e5e788b4bcd6db3a40c4e24bdf (patch)
treea94e8f9820d5be230ca26883a9efdaa57f6a2ba8
parent554f7298707cd5f2ae0aef8a4c9e215bcd3616ff (diff)
downloadpoi-3247a4160e9ba6e5e788b4bcd6db3a40c4e24bdf.tar.gz
poi-3247a4160e9ba6e5e788b4bcd6db3a40c4e24bdf.zip
[github-364] use Math.min/max. Thanks to Arturo Bernal. This closes #364
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1903256 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTListing.java3
-rw-r--r--poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java9
-rw-r--r--poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java8
-rw-r--r--poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java2
-rw-r--r--poi/src/main/java/org/apache/poi/ss/usermodel/FractionFormat.java2
5 files changed, 9 insertions, 15 deletions
diff --git a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTListing.java b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTListing.java
index c3cdac64a8..01265de7ca 100644
--- a/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTListing.java
+++ b/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTListing.java
@@ -76,8 +76,7 @@ public final class SLWTListing {
}
// Report the first 5 children, to give a flavour
- int upTo = 5;
- if(children.length < 5) { upTo = children.length; }
+ int upTo = Math.min(children.length, 5);
for(int k=0; k<upTo; k++) {
Record r = children[k];
int typeID = (int)r.getRecordType();
diff --git a/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java b/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java
index 96ba6c4e98..44d31728c6 100644
--- a/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java
+++ b/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java
@@ -218,13 +218,8 @@ public final class HeaderBlock implements HeaderBlockConstants {
}
private static IOException alertShortRead(int pRead) {
- int read;
- if (pRead < 0) {
- //Can't have -1 bytes read in the error message!
- read = 0;
- } else {
- read = pRead;
- }
+ int read = Math.max(pRead, 0);
+ //Can't have -1 bytes read in the error message!
String type = " byte" + (read == 1 ? (""): ("s"));
return new IOException("Unable to read entire header; "
diff --git a/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java b/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java
index 69b5a6e320..7873984377 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java
@@ -152,8 +152,8 @@ public class WorkdayCalculator {
*/
protected int pastDaysOfWeek(double start, double end, int dayOfWeek) {
int pastDaysOfWeek = 0;
- int startDay = (int) Math.floor(start < end ? start : end);
- int endDay = (int) Math.floor(end > start ? end : start);
+ int startDay = (int) Math.floor(Math.min(start, end));
+ int endDay = (int) Math.floor(Math.max(end, start));
for (; startDay <= endDay; startDay++) {
Calendar today = LocaleUtil.getLocaleCalendar();
today.setTime(DateUtil.getJavaDate(startDay));
@@ -174,8 +174,8 @@ public class WorkdayCalculator {
*/
protected int calculateNonWeekendHolidays(double start, double end, double[] holidays) {
int nonWeekendHolidays = 0;
- double startDay = start < end ? start : end;
- double endDay = end > start ? end : start;
+ double startDay = Math.min(start, end);
+ double endDay = Math.max(end, start);
for (double holiday : holidays) {
if (isInARange(startDay, endDay, holiday)) {
if (!isWeekend(holiday)) {
diff --git a/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java b/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
index 4402ed49d7..bc0ccfe482 100644
--- a/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
+++ b/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
@@ -104,7 +104,7 @@ public abstract class NumericFunction implements Function {
}
DecimalFormat nf = (DecimalFormat) NumberFormat.getCurrencyInstance(LocaleUtil.getUserLocale());
- int decimalPlaces = nPlaces < 0 ? 0 : nPlaces;
+ int decimalPlaces = Math.max(nPlaces, 0);
if (LocaleUtil.getUserLocale().getCountry().equalsIgnoreCase("US")) {
nf.setNegativePrefix("(" + nf.getDecimalFormatSymbols().getCurrencySymbol());
nf.setNegativeSuffix(")");
diff --git a/poi/src/main/java/org/apache/poi/ss/usermodel/FractionFormat.java b/poi/src/main/java/org/apache/poi/ss/usermodel/FractionFormat.java
index da1abe6b6e..75c343b33f 100644
--- a/poi/src/main/java/org/apache/poi/ss/usermodel/FractionFormat.java
+++ b/poi/src/main/java/org/apache/poi/ss/usermodel/FractionFormat.java
@@ -90,7 +90,7 @@ public class FractionFormat extends Format {
}
} else if (m.group(1) != null) {
int len = m.group(1).length();
- len = len > MAX_DENOM_POW ? MAX_DENOM_POW : len;
+ len = Math.min(len, MAX_DENOM_POW);
tmpMax = (int)Math.pow(10, len);
} else {
tmpExact = 100;