commons-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From er...@apache.org
Subject [commons-numbers] 01/04: [commons-number] replace some compares with their function
Date Mon, 16 Dec 2019 12:28:22 GMT
This is an automated email from the ASF dual-hosted git repository.

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

commit 3b3743f24ebf033f153a3961f3fa2fefcf05d6b8
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