]> source.dussan.org Git - poi.git/commitdiff
Use Integer.compare() where possible
authorDominik Stadler <centic@apache.org>
Sat, 16 Sep 2017 08:29:20 +0000 (08:29 +0000)
committerDominik Stadler <centic@apache.org>
Sat, 16 Sep 2017 08:29:20 +0000 (08:29 +0000)
git-svn-id: https://svn.apache.org/repos/asf/poi/trunk@1808522 13f79535-47bb-0310-9956-ffa450edef68

src/java/org/apache/poi/ddf/AbstractEscherOptRecord.java
src/java/org/apache/poi/ss/formula/EvaluationConditionalFormatRule.java
src/java/org/apache/poi/ss/util/NumberComparer.java
src/ooxml/java/org/apache/poi/xssf/util/CTColComparator.java
src/scratchpad/src/org/apache/poi/hsmf/datatypes/RecipientChunks.java
src/scratchpad/src/org/apache/poi/hsmf/dev/TypesLister.java
src/scratchpad/src/org/apache/poi/hwpf/converter/AbstractWordConverter.java
src/scratchpad/src/org/apache/poi/hwpf/model/PropertyNode.java
src/scratchpad/src/org/apache/poi/hwpf/model/TextPieceTable.java
src/scratchpad/src/org/apache/poi/hwpf/usermodel/FieldsImpl.java
src/testcases/org/apache/poi/ss/util/TestNumberComparer.java

index 6009b005221758c210069f45b2506a84be3326d8..ff4a3e80dede9795641bce6badd0d7e805974d94 100644 (file)
@@ -142,7 +142,7 @@ public abstract class AbstractEscherOptRecord extends EscherRecord
             {
                 short s1 = p1.getPropertyNumber();
                 short s2 = p2.getPropertyNumber();
-                return s1 < s2 ? -1 : s1 == s2 ? 0 : 1;
+                return Short.compare(s1, s2);
             }
         } );
     }
index 6c39634117a9a4651723960dad1f0195db6a667c..ecd61ace5e92bb82f25d93a714c9187280d1ccb7 100644 (file)
@@ -242,16 +242,16 @@ public class EvaluationConditionalFormatRule implements Comparable<EvaluationCon
         final int x = getPriority();
         final int y = o.getPriority();
         // logic from Integer.compare()
-        cmp = (x < y) ? -1 : ((x == y) ? 0 : 1);
+        cmp = Integer.compare(x, y);
         if (cmp != 0) {
             return cmp;
         }
 
-        cmp = new Integer(getFormattingIndex()).compareTo(new Integer(o.getFormattingIndex()));
+        cmp = Integer.compare(getFormattingIndex(), o.getFormattingIndex());
         if (cmp != 0) {
             return cmp;
         }
-        return new Integer(getRuleIndex()).compareTo(new Integer(o.getRuleIndex()));
+        return Integer.compare(getRuleIndex(), o.getRuleIndex());
     }
     
     @Override
index 56648126e6e1a3597a67204df60d00d9f9dbe5dc..bf903ffa921198f68de11fece6e21dad3f52f27c 100644 (file)
@@ -131,7 +131,7 @@ public final class NumberComparer {
         * If both numbers are subnormal, Excel seems to use standard comparison rules
         */
        private static int compareSubnormalNumbers(long fracA, long fracB, boolean isNegative) {
-               int cmp = fracA > fracB ? +1 : fracA < fracB ? -1 : 0;
+               int cmp = Long.compare(fracA, fracB);
 
                return isNegative ? -cmp : cmp;
        }
index 5368eb0e6e931350423b7f488c4f37e8eed91e8f..ef8e526a4357dcb68024c52e7169a404d517be36 100644 (file)
@@ -30,7 +30,7 @@ public class CTColComparator {
         public int compare(CTCol col1, CTCol col2) {
             long col1max = col1.getMax();
             long col2max = col2.getMax();
-            return col1max < col2max ? -1 : col1max > col2max ? 1 : 0;
+            return Long.compare(col1max, col2max);
         }
     };
 
index 6680cde92289597206f448f8b3f20432c6a39868..e9241845fd5a983aa6c4fd4a73b770b8d3084c4d 100644 (file)
@@ -222,13 +222,7 @@ public final class RecipientChunks implements ChunkGroupWithProperties {
             implements Comparator<RecipientChunks>, Serializable {
         @Override
         public int compare(RecipientChunks a, RecipientChunks b) {
-            if (a.recipientNumber < b.recipientNumber) {
-                return -1;
-            }
-            if (a.recipientNumber > b.recipientNumber) {
-                return +1;
-            }
-            return 0;
+            return Integer.compare(a.recipientNumber, b.recipientNumber);
         }
     }
 }
index a3bc793ac8ace6c087fd32e2506591c8321b0d9f..663b8061476b54bbe6963fc1151741d04ce29df6 100644 (file)
@@ -43,9 +43,7 @@ public class TypesLister {
       ArrayList<MAPIProperty> all = new ArrayList<>(MAPIProperty.getAll());
       Collections.sort(all, new Comparator<MAPIProperty>() {
          public int compare(MAPIProperty a, MAPIProperty b) {
-            if(a.id < b.id) return -1;
-            if(a.id > b.id) return +1;
-            return 0;
+             return Integer.compare(a.id, b.id);
          }
       });
       list(all, out);
index 0a29f0b7dc08148861ca652d1a2f92f8101132e2..b5ec864ff19215eb8cf32fc1fdc573e77c08f343 100644 (file)
@@ -102,7 +102,7 @@ public abstract class AbstractWordConverter
 
         public int compareTo( Structure o )
         {
-            return start < o.start ? -1 : start == o.start ? 0 : 1;
+            return Integer.compare(start, o.start);
         }
 
         @Override
index 2b307e1995d0b15fcf0948b1a50074924c2e841b..a0e0fec6e4d776a664f41a3e578f9c6c65b9109c 100644 (file)
@@ -43,8 +43,7 @@ public abstract class PropertyNode<T extends PropertyNode<T>> implements Compara
         public int compare(PropertyNode<?> o1, PropertyNode<?> o2) {
             int thisVal = o1.getEnd();
             int anotherVal = o2.getEnd();
-            return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0
-                    : 1));
+            return (Integer.compare(thisVal, anotherVal));
         }
     }
 
@@ -55,8 +54,7 @@ public abstract class PropertyNode<T extends PropertyNode<T>> implements Compara
         public int compare(PropertyNode<?> o1, PropertyNode<?> o2) {
             int thisVal = o1.getStart();
             int anotherVal = o2.getStart();
-            return (thisVal < anotherVal ? -1 : (thisVal == anotherVal ? 0
-                    : 1));
+            return (Integer.compare(thisVal, anotherVal));
         }
     }
 
@@ -175,12 +173,6 @@ public abstract class PropertyNode<T extends PropertyNode<T>> implements Compara
      */
     public int compareTo(T o) {
         int cpEnd = o.getEnd();
-        if (_cpEnd == cpEnd) {
-            return 0;
-        } else if (_cpEnd < cpEnd) {
-            return -1;
-        } else {
-            return 1;
-        }
+        return Integer.compare(_cpEnd, cpEnd);
     }
 }
index 16c78e6e1aa9d8b7e6ebae85c10f6ea5b6aec880..ee14b50e1ec49e47c3bc14ffe6186d2752715c83 100644 (file)
@@ -449,15 +449,8 @@ public class TextPieceTable implements CharIndexTranslator {
 
     protected static class FCComparator implements Comparator<TextPiece>, Serializable {
         public int compare(TextPiece textPiece, TextPiece textPiece1) {
-            if (textPiece.getPieceDescriptor().fc > textPiece1
-                    .getPieceDescriptor().fc) {
-                return 1;
-            } else if (textPiece.getPieceDescriptor().fc < textPiece1
-                    .getPieceDescriptor().fc) {
-                return -1;
-            } else {
-                return 0;
-            }
+            return Integer.compare(textPiece.getPieceDescriptor().fc, textPiece1
+                    .getPieceDescriptor().fc);
         }
     }
 }
index b4c972d87f9d6afc8ad2a45dfd75914d1209f236..90a629235b2b672c562470a729a9b8d2fa77ab3f 100644 (file)
@@ -267,7 +267,7 @@ public class FieldsImpl implements Fields
         {
             int thisVal = o1.getFcStart();
             int anotherVal = o2.getFcStart();
-            return thisVal < anotherVal ? -1 : thisVal == anotherVal ? 0 : 1;
+            return Integer.compare(thisVal, anotherVal);
         }
     }
 
index 33cf09ad755af84c025cd00dc05b6efcfd11acd4..b48ebee5a7e9ed9cced5935188943e5036d661ed 100644 (file)
@@ -93,7 +93,7 @@ public final class TestNumberComparer {
        private static boolean confirm(int i, double a, double b, int expRes) {
                int actRes = NumberComparer.compare(a, b);
 
-               int sgnActRes = actRes < 0 ? -1 : actRes > 0 ? +1 : 0;
+               int sgnActRes = Integer.compare(actRes, 0);
                if (sgnActRes != expRes) {
                        System.err.println("Mismatch example[" + i + "] ("
                                        + formatDoubleAsHex(a) + ", " + formatDoubleAsHex(b) + ") expected "