--- a/jdk/src/share/classes/java/lang/Integer.java Tue Sep 22 18:30:58 2009 -0700
+++ b/jdk/src/share/classes/java/lang/Integer.java Tue Sep 22 18:30:58 2009 -0700
@@ -1010,9 +1010,25 @@
* @since 1.2
*/
public int compareTo(Integer anotherInteger) {
- int thisVal = this.value;
- int anotherVal = anotherInteger.value;
- return (thisVal<anotherVal ? -1 : (thisVal==anotherVal ? 0 : 1));
+ return compare(this.value, anotherInteger.value);
+ }
+
+ /**
+ * Compares two {@code int} values numerically.
+ * The value returned is identical to what would be returned by:
+ * <pre>
+ * Integer.valueOf(x).compareTo(Integer.valueOf(y))
+ * </pre>
+ *
+ * @param x the first {@code int} to compare
+ * @param y the second {@code int} 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(int x, int y) {
+ return (x < y) ? -1 : ((x == y) ? 0 : 1);
}