Author: fanningpj
Date: Sat Aug  6 20:51:57 2022
New Revision: 1903256

URL: http://svn.apache.org/viewvc?rev=1903256&view=rev
Log:
[github-364] use Math.min/max. Thanks to Arturo Bernal. This closes #364

Modified:
    
poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTListing.java
    poi/trunk/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java
    
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java
    
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
    poi/trunk/poi/src/main/java/org/apache/poi/ss/usermodel/FractionFormat.java

Modified: 
poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTListing.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTListing.java?rev=1903256&r1=1903255&r2=1903256&view=diff
==============================================================================
--- 
poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTListing.java 
(original)
+++ 
poi/trunk/poi-scratchpad/src/main/java/org/apache/poi/hslf/dev/SLWTListing.java 
Sat Aug  6 20:51:57 2022
@@ -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();

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java?rev=1903256&r1=1903255&r2=1903256&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java 
(original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/poifs/storage/HeaderBlock.java 
Sat Aug  6 20:51:57 2022
@@ -218,13 +218,8 @@ public final class HeaderBlock implement
     }
 
     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; "

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java?rev=1903256&r1=1903255&r2=1903256&view=diff
==============================================================================
--- 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java
 (original)
+++ 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/atp/WorkdayCalculator.java
 Sat Aug  6 20:51:57 2022
@@ -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)) {

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java?rev=1903256&r1=1903255&r2=1903256&view=diff
==============================================================================
--- 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
 (original)
+++ 
poi/trunk/poi/src/main/java/org/apache/poi/ss/formula/functions/NumericFunction.java
 Sat Aug  6 20:51:57 2022
@@ -104,7 +104,7 @@ public abstract class NumericFunction im
             }
 
             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(")");

Modified: 
poi/trunk/poi/src/main/java/org/apache/poi/ss/usermodel/FractionFormat.java
URL: 
http://svn.apache.org/viewvc/poi/trunk/poi/src/main/java/org/apache/poi/ss/usermodel/FractionFormat.java?rev=1903256&r1=1903255&r2=1903256&view=diff
==============================================================================
--- poi/trunk/poi/src/main/java/org/apache/poi/ss/usermodel/FractionFormat.java 
(original)
+++ poi/trunk/poi/src/main/java/org/apache/poi/ss/usermodel/FractionFormat.java 
Sat Aug  6 20:51:57 2022
@@ -90,7 +90,7 @@ public class FractionFormat extends Form
                 }
             } 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;



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to