You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@commons.apache.org by gg...@apache.org on 2025/09/06 14:50:56 UTC

(commons-lang) branch master updated: Deprecate NumberUtils.compare(int, int) in favor of Integer.compare(int, int)

This is an automated email from the ASF dual-hosted git repository.

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


The following commit(s) were added to refs/heads/master by this push:
     new 1d9093c50 Deprecate NumberUtils.compare(int, int) in favor of Integer.compare(int, int)
1d9093c50 is described below

commit 1d9093c5062806db6c13ec635648c71aeac6a09f
Author: Gary D. Gregory <ga...@gmail.com>
AuthorDate: Sat Sep 6 07:50:50 2025 -0700

    Deprecate NumberUtils.compare(int, int) in favor of Integer.compare(int,
    int)
---
 src/changes/changes.xml                                        | 1 +
 src/main/java/org/apache/commons/lang3/ArrayUtils.java         | 2 +-
 src/main/java/org/apache/commons/lang3/math/NumberUtils.java   | 7 +++----
 src/main/java/org/apache/commons/lang3/mutable/MutableInt.java | 8 +++-----
 4 files changed, 8 insertions(+), 10 deletions(-)

diff --git a/src/changes/changes.xml b/src/changes/changes.xml
index 38270c28b..29f1b2b79 100644
--- a/src/changes/changes.xml
+++ b/src/changes/changes.xml
@@ -62,6 +62,7 @@ The <action> type attribute can be add,update,fix,remove.
     <action                   type="fix" dev="ggregory" due-to="mayuming">Fix CalendarUtils.toLocalDate() Javadoc return type description #1440.</action>
     <action                   type="fix" dev="ggregory" due-to="mayuming">Fix the method name in Javadoc examples for CharUtils.isHex() #1444.</action>
     <action                   type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate NumberUtils.compare(byte, byte) in favor of Byte.compare(byte, byte).</action>
+    <action                   type="fix" dev="ggregory" due-to="Gary Gregory">Deprecate NumberUtils.compare(int, int) in favor of Integer.compare(int, int).</action>
     <!-- FIX Javadoc -->
     <action                   type="fix" dev="ggregory" due-to="Gary Gregory">[javadoc] General improvements.</action>
     <action                   type="fix" dev="ggregory" due-to="Gary Gregory">[javadoc] Fix thrown exception documentation for org.apache.commons.lang3.reflect.MethodUtils.getMethodObject(Class&lt;?&gt;, String, Class&lt;?&gt;...).</action>
diff --git a/src/main/java/org/apache/commons/lang3/ArrayUtils.java b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
index 73ac6cb80..2c32cd09e 100644
--- a/src/main/java/org/apache/commons/lang3/ArrayUtils.java
+++ b/src/main/java/org/apache/commons/lang3/ArrayUtils.java
@@ -3714,7 +3714,7 @@ public static boolean isSorted(final int[] array) {
         final int n = array.length;
         for (int i = 1; i < n; i++) {
             final int current = array[i];
-            if (NumberUtils.compare(previous, current) > 0) {
+            if (Integer.compare(previous, current) > 0) {
                 return false;
             }
             previous = current;
diff --git a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
index 01c2bf7d4..537c98fdb 100644
--- a/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
+++ b/src/main/java/org/apache/commons/lang3/math/NumberUtils.java
@@ -111,12 +111,11 @@ public static int compare(final byte x, final byte y) {
      *         a value less than {@code 0} if {@code x < y}; and
      *         a value greater than {@code 0} if {@code x > y}
      * @since 3.4
+     * @deprecated Use {@link Integer#compare(int, int)}.
      */
+    @Deprecated
     public static int compare(final int x, final int y) {
-        if (x == y) {
-            return 0;
-        }
-        return x < y ? -1 : 1;
+        return Integer.compare(x, y);
     }
 
     /**
diff --git a/src/main/java/org/apache/commons/lang3/mutable/MutableInt.java b/src/main/java/org/apache/commons/lang3/mutable/MutableInt.java
index 9147c89ee..fcb11e510 100644
--- a/src/main/java/org/apache/commons/lang3/mutable/MutableInt.java
+++ b/src/main/java/org/apache/commons/lang3/mutable/MutableInt.java
@@ -18,8 +18,6 @@
 
 import java.util.concurrent.atomic.AtomicInteger;
 
-import org.apache.commons.lang3.math.NumberUtils;
-
 /**
  * A mutable {@code int} wrapper.
  * <p>
@@ -132,12 +130,12 @@ public int addAndGet(final Number operand) {
     /**
      * Compares this mutable to another in ascending order.
      *
-     * @param other  the other mutable to compare to, not null
-     * @return negative if this is less, zero if equal, positive if greater
+     * @param other  the other mutable to compare to, not null.
+     * @return negative if this is less, zero if equal, positive if greater.
      */
     @Override
     public int compareTo(final MutableInt other) {
-        return NumberUtils.compare(this.value, other.value);
+        return Integer.compare(this.value, other.value);
     }
 
     /**