commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From aherb...@apache.org
Subject [commons-numbers] branch master updated: [commons-number] replace some compares with their function
Date Mon, 16 Dec 2019 11:06:39 GMT
This is an automated email from the ASF dual-hosted git repository.

aherbert pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/commons-numbers.git


The following commit(s) were added to refs/heads/master by this push:
     new 2b57125  [commons-number] replace some compares with their function
     new c642c8f  Merge pull request #73 from grimreaper/eax/long-compare-mode
2b57125 is described below

commit 2b5712523a7e08663acc80721938b043eab78a60
Author: Eitan Adler <lists@eitanadler.com>
AuthorDate: Sun Dec 15 22:38:30 2019 -0800

    [commons-number] replace some compares with their function
    
    Replace explicit logic of comparing longs with the function that does
    so.
---
 .../org/apache/commons/numbers/combinatorics/Combinations.java    | 8 +-------
 .../main/java/org/apache/commons/numbers/fraction/Fraction.java   | 4 +---
 2 files changed, 2 insertions(+), 10 deletions(-)

diff --git a/commons-numbers-combinatorics/src/main/java/org/apache/commons/numbers/combinatorics/Combinations.java
b/commons-numbers-combinatorics/src/main/java/org/apache/commons/numbers/combinatorics/Combinations.java
index 3db4ae7..86ef55a 100644
--- a/commons-numbers-combinatorics/src/main/java/org/apache/commons/numbers/combinatorics/Combinations.java
+++ b/commons-numbers-combinatorics/src/main/java/org/apache/commons/numbers/combinatorics/Combinations.java
@@ -350,13 +350,7 @@ public final class Combinations implements Iterable<int[]> {
             final long v1 = lexNorm(c1s);
             final long v2 = lexNorm(c2s);
 
-            if (v1 < v2) {
-                return -1;
-            } else if (v1 > v2) {
-                return 1;
-            } else {
-                return 0;
-            }
+            return Long.compare(v1, v2);
         }
 
         /**
diff --git a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
index a70f3a2..2f5cc27 100644
--- a/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
+++ b/commons-numbers-fraction/src/main/java/org/apache/commons/numbers/fraction/Fraction.java
@@ -280,9 +280,7 @@ public final class Fraction
     public int compareTo(Fraction object) {
         final long nOd = ((long) numerator) * object.denominator;
         final long dOn = ((long) denominator) * object.numerator;
-        return nOd < dOn ? -1 :
-            nOd > dOn ? 1 :
-            0;
+        return Long.compare(nOd, dOn);
     }
 
     /**


Mime
View raw message