groovy-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From sun...@apache.org
Subject [2/2] groovy git commit: Trivial refactoring: use `compare` instead to simplify code
Date Thu, 05 Jul 2018 07:31:44 GMT
Trivial refactoring: use `compare` instead to simplify code

(cherry picked from commit bb9b874)


Project: http://git-wip-us.apache.org/repos/asf/groovy/repo
Commit: http://git-wip-us.apache.org/repos/asf/groovy/commit/b57212ba
Tree: http://git-wip-us.apache.org/repos/asf/groovy/tree/b57212ba
Diff: http://git-wip-us.apache.org/repos/asf/groovy/diff/b57212ba

Branch: refs/heads/GROOVY_2_5_X
Commit: b57212ba3ee6057df78f67aa4f4558b5e6f267ba
Parents: 362e218
Author: sunlan <sunlan@apache.org>
Authored: Thu Jul 5 14:32:49 2018 +0800
Committer: sunlan <sunlan@apache.org>
Committed: Thu Jul 5 15:31:30 2018 +0800

----------------------------------------------------------------------
 .../java/org/codehaus/groovy/runtime/typehandling/IntegerMath.java | 2 +-
 .../java/org/codehaus/groovy/runtime/typehandling/LongMath.java    | 2 +-
 2 files changed, 2 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/groovy/blob/b57212ba/src/main/java/org/codehaus/groovy/runtime/typehandling/IntegerMath.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/typehandling/IntegerMath.java b/src/main/java/org/codehaus/groovy/runtime/typehandling/IntegerMath.java
index 7fbc6aa..5734553 100644
--- a/src/main/java/org/codehaus/groovy/runtime/typehandling/IntegerMath.java
+++ b/src/main/java/org/codehaus/groovy/runtime/typehandling/IntegerMath.java
@@ -52,7 +52,7 @@ public final class IntegerMath extends NumberMath {
     public int compareToImpl(Number left, Number right) {
         int leftVal = left.intValue();
         int rightVal = right.intValue();
-        return (leftVal<rightVal ? -1 : (leftVal==rightVal ? 0 : 1));
+        return Integer.compare(leftVal, rightVal);
     }
 
     protected Number orImpl(Number left, Number right) {

http://git-wip-us.apache.org/repos/asf/groovy/blob/b57212ba/src/main/java/org/codehaus/groovy/runtime/typehandling/LongMath.java
----------------------------------------------------------------------
diff --git a/src/main/java/org/codehaus/groovy/runtime/typehandling/LongMath.java b/src/main/java/org/codehaus/groovy/runtime/typehandling/LongMath.java
index e7f2d6e..d489bb4 100644
--- a/src/main/java/org/codehaus/groovy/runtime/typehandling/LongMath.java
+++ b/src/main/java/org/codehaus/groovy/runtime/typehandling/LongMath.java
@@ -52,7 +52,7 @@ public final class LongMath extends NumberMath {
     public int compareToImpl(Number left, Number right) {
         long leftVal = left.longValue();
         long rightVal = right.longValue();
-        return (leftVal<rightVal ? -1 : (leftVal==rightVal ? 0 : 1));
+        return Long.compare(leftVal, rightVal);
     }
 
     protected Number intdivImpl(Number left, Number right) {


Mime
View raw message