Index: java/lang/Float.java
===================================================================
RCS file: /cvs/classpath/java/lang/Float.java,v
retrieving revision 1.13
diff -u -u -r1.13 Float.java
--- java/lang/Float.java 2000/03/16 23:31:24 1.13
+++ java/lang/Float.java 2001/01/07 22:26:30
@@ -1,5 +1,5 @@
/* java.lang.Float
- Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -37,7 +37,7 @@
* @author Paul Fisher
* @since JDK 1.0
*/
-public final class Float extends Number
+public final class Float extends Number implements Comparable
{
/**
* The minimum positive value a float
may represent
@@ -387,4 +387,58 @@
*/
public native static float parseFloat(String s)
throws NumberFormatException, NullPointerException;
+
+ /**
+ * Returns 0 if the float
value of the argument is
+ * equal to the value of this Float
. Returns a number
+ * less than zero if the value of this Float
is less
+ * than the Float
value of the argument, and returns a
+ * number greater than zero if the value of this Float
+ * is greater than the float
value of the argument.
+ *
+ * Float.NaN
is greater than any number other than itself,
+ * even Float.POSITIVE_INFINITY
.
+ *
+ * 0.0
is greater than -0.0
.
+ *
+ * @param f the Float to compare to.
+ * @return 0 if the Float
s are the same, < 0 if this
+ * Float
is less than the Float
in
+ * in question, or > 0 if it is greater.
+ *
+ * @since 1.2
+ */
+ public int compareTo(Float f)
+ {
+ float x = f.floatValue();
+
+ if (value == NaN)
+ return (x == NaN) ? 0 : 1;
+ if ((value == 0.0) && (x == -0.0))
+ return 1;
+ if ((value == -0.0) && (x == 0.0))
+ return -1;
+
+ return ((value - x) > 0) ? 1 : -1;
+ }
+
+ /**
+ * Compares the specified Object
to this Float
+ * if and only if the Object
is an instanceof
+ * Float
.
+ * Otherwise it throws a ClassCastException
+ *
+ * @param o the Object to compare to.
+ * @return 0 if the Float
s are the same, < 0 if this
+ * Float
is less than the Float
in
+ * in question, or > 0 if it is greater.
+ * @throws ClassCastException if the argument is not a Float
+ *
+ * @since 1.2
+ */
+ public int compareTo(Object o)
+ {
+ return compareTo((Float)o);
+ }
+
}
Index: java/lang/Integer.java
===================================================================
RCS file: /cvs/classpath/java/lang/Integer.java,v
retrieving revision 1.15
diff -u -u -r1.15 Integer.java
--- java/lang/Integer.java 2000/03/16 23:31:28 1.15
+++ java/lang/Integer.java 2001/01/07 22:26:30
@@ -1,5 +1,5 @@
/* java.lang.Integer
- Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,7 +38,7 @@
* @author John Keiser
* @since JDK 1.0
*/
-public final class Integer extends Number {
+public final class Integer extends Number implements Comparable {
// compatible with JDK 1.0.2+
static final long serialVersionUID = 1360826667806852920L;
@@ -456,4 +456,36 @@
public double doubleValue() {
return value;
}
+
+ /**
+ * Compare two Integers numerically by comparing their
+ * int
values.
+ * @return a positive value if this Integer
is greater
+ * in value than the argument Integer
; a negative value
+ * if this Integer
is smaller in value than the argument
+ * Integer
; and 0
, zero, if this
+ * Integer
is equal in value to the argument
+ * Integer
.
+ *
+ * @since 1.2
+ */
+ public int compareTo(Integer i)
+ {
+ return (value - i.intValue());
+ }
+
+ /**
+ * Behaves like compareTo(java.lang.Integer)
unless the Object
+ * is not a Integer
. Then it throws a
+ * ClassCastException
.
+ * @exception ClassCastException if the argument is not a
+ * Integer
.
+ *
+ * @since 1.2
+ */
+ public int compareTo(Object o)
+ {
+ return compareTo((Integer)o);
+ }
+
}
Index: java/lang/Long.java
===================================================================
RCS file: /cvs/classpath/java/lang/Long.java,v
retrieving revision 1.8
diff -u -u -r1.8 Long.java
--- java/lang/Long.java 2000/03/16 23:31:30 1.8
+++ java/lang/Long.java 2001/01/07 22:26:31
@@ -1,5 +1,5 @@
/* java.lang.Long
- Copyright (C) 1998, 1999 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,7 +38,7 @@
* @author John Keiser
* @since JDK 1.0
*/
-public final class Long extends Number {
+public final class Long extends Number implements Comparable {
// compatible with JDK 1.0.2+
static final long serialVersionUID = 4290774380558885855L;
@@ -442,4 +442,36 @@
public double doubleValue() {
return value;
}
+
+ /**
+ * Compare two Longs numerically by comparing their
+ * long
values.
+ * @return a positive value if this Long
is greater
+ * in value than the argument Long
; a negative value
+ * if this Long
is smaller in value than the argument
+ * Long
; and 0
, zero, if this
+ * Long
is equal in value to the argument
+ * Long
.
+ *
+ * @since 1.2
+ */
+ public int compareTo(Long l)
+ {
+ return (int)(value - l.longValue());
+ }
+
+ /**
+ * Behaves like compareTo(java.lang.Long)
unless the Object
+ * is not a Long
. Then it throws a
+ * ClassCastException
.
+ * @exception ClassCastException if the argument is not a
+ * Long
.
+ *
+ * @since 1.2
+ */
+ public int compareTo(Object o)
+ {
+ return compareTo((Long)o);
+ }
+
}
Index: java/lang/Short.java
===================================================================
RCS file: /cvs/classpath/java/lang/Short.java,v
retrieving revision 1.7
diff -u -u -r1.7 Short.java
--- java/lang/Short.java 2000/03/16 23:31:38 1.7
+++ java/lang/Short.java 2001/01/07 22:26:31
@@ -1,5 +1,5 @@
/* java.lang.Short
- Copyright (C) 1998 Free Software Foundation, Inc.
+ Copyright (C) 1998, 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -38,7 +38,7 @@
* @author John Keiser
* @since JDK 1.0
*/
-public final class Short extends Number {
+public final class Short extends Number implements Comparable {
static final long serialVersionUID = 7515723908773894738L;
@@ -335,4 +335,36 @@
public double doubleValue() {
return value;
}
+
+ /**
+ * Compare two Shorts numerically by comparing their
+ * short
values.
+ * @return a positive value if this Short
is greater
+ * in value than the argument Short
; a negative value
+ * if this Short
is smaller in value than the argument
+ * Short
; and 0
, zero, if this
+ * Short
is equal in value to the argument
+ * Short
.
+ *
+ * @since 1.2
+ */
+ public int compareTo(Short s)
+ {
+ return (value - s.shortValue());
+ }
+
+ /**
+ * Behaves like compareTo(java.lang.Short)
unless the Object
+ * is not a Short
. Then it throws a
+ * ClassCastException
.
+ * @exception ClassCastException if the argument is not a
+ * Short
.
+ *
+ * @since 1.2
+ */
+ public int compareTo(Object o)
+ {
+ return compareTo((Short)o);
+ }
+
}
Index: java/lang/String.java
===================================================================
RCS file: /cvs/classpath/java/lang/String.java,v
retrieving revision 1.29
diff -u -u -r1.29 String.java
--- java/lang/String.java 2000/07/28 17:22:03 1.29
+++ java/lang/String.java 2001/01/07 22:26:31
@@ -1,5 +1,5 @@
/* java.lang.String
- Copyright (C) 1998, 1999, 2000 Free Software Foundation, Inc.
+ Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation, Inc.
This file is part of GNU Classpath.
@@ -27,6 +27,7 @@
package java.lang;
+import java.util.Comparator;
import java.util.Hashtable;
import java.util.Locale;
import gnu.java.io.EncodingManager;
@@ -39,7 +40,7 @@
* @author Paul N. Fisher
* @since JDK1.0
*/
-public final class String {
+public final class String implements Comparable {
/**
* Holds the references for each intern()'d String.
* Once a String has been intern()'d it cannot be GC'd.
@@ -78,6 +79,18 @@
private int cachedHashCode;
/**
+ * A Comparator that uses String.compareToIgnoreCase(String)
.
+ *
+ * @since 1.2
+ */
+ public static final Comparator CASE_INSENSITIVE_ORDER
+ = new Comparator() {
+ public int compare(Object o1, Object o2) {
+ return ((String)o1).compareToIgnoreCase((String)o2);
+ }
+ };
+
+ /**
* Creates an empty String (length 0)
*/
public String() {
@@ -519,6 +532,43 @@
return result;
}
return count-anotherString.count;
+ }
+
+ /**
+ * Behaves like compareTo(java.lang.String)
unless the Object
+ * is not a String
. Then it throws a
+ * ClassCastException
.
+ * @exception ClassCastException if the argument is not a
+ * String
.
+ *
+ * @since 1.2
+ */
+ public int compareTo(Object o)
+ {
+ return compareTo((String)o);
+ }
+
+ /**
+ * Compares this String and another String (case insensitive).
+ *
+ * @return returns an integer less than, equal to, or greater than
+ * zero, if this String is found, respectively, to be less than,
+ * to match, or be greater than the given String.
+ *
+ * @since 1.2
+ */
+ public int compareToIgnoreCase(String s)
+ {
+ int min = Math.min(count, s.count);
+ for (int i = 0; i < min; i++)
+ {
+ char c1 = Character.toLowerCase(Character.toUpperCase(value[i]));
+ char c2 = Character.toLowerCase(Character.toUpperCase(s.value[i]));
+ int result = c1 - c2;
+ if (result != 0)
+ return result;
+ }
+ return count-s.count;
}
/**