jdk/src/share/classes/java/lang/Long.java
changeset 3943 11abf5578222
parent 3288 db82a42da273
child 3964 cf913644be58
--- a/jdk/src/share/classes/java/lang/Long.java	Tue Sep 22 18:30:58 2009 -0700
+++ b/jdk/src/share/classes/java/lang/Long.java	Tue Sep 22 18:30:58 2009 -0700
@@ -950,9 +950,25 @@
      * @since   1.2
      */
     public int compareTo(Long anotherLong) {
-        long thisVal = this.value;
-        long anotherVal = anotherLong.value;
-        return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
+        return compare(this.value, anotherLong.value);
+    }
+
+    /**
+     * Compares two {@code long} values numerically.
+     * The value returned is identical to what would be returned by:
+     * <pre>
+     *    Long.valueOf(x).compareTo(Long.valueOf(y))
+     * </pre>
+     *
+     * @param  x the first {@code long} to compare
+     * @param  y the second {@code long} to compare
+     * @return the value {@code 0} if {@code x == y};
+     *         a value less than {@code 0} if {@code x < y}; and
+     *         a value greater than {@code 0} if {@code x > y}
+     * @since 1.7
+     */
+    public static int compare(long x, long y) {
+        return (x < y) ? -1 : ((x == y) ? 0 : 1);
     }