This is the mail archive of the
java-patches@gcc.gnu.org
mailing list for the Java project.
Patch: FYI: CASE_INSENSITIVE_ORDER fix
- To: Java Patch List <java-patches at gcc dot gnu dot org>
- Subject: Patch: FYI: CASE_INSENSITIVE_ORDER fix
- From: Tom Tromey <tromey at redhat dot com>
- Date: 05 Sep 2001 13:44:10 -0600
- Reply-To: tromey at redhat dot com
This patch is adapted from a similar Classpath patch.
String.CASE_INSENSITIVE_ORDER is required to implement Serializable.
I'm checking this in.
Tom
Index: ChangeLog
from Tom Tromey <tromey@redhat.com>
From Eric Blake, via Classpath:
* java/lang/String.java (CaseInsensitiveComparator): New class.
(CASE_INSENSITIVE_ORDER): Use instance of CaseInsensitiveComparator.
Index: java/lang/String.java
===================================================================
RCS file: /cvs/gcc/gcc/libjava/java/lang/String.java,v
retrieving revision 1.14
diff -u -r1.14 String.java
--- java/lang/String.java 2001/05/22 04:38:35 1.14
+++ java/lang/String.java 2001/09/05 19:12:48
@@ -1,4 +1,4 @@
-/* Copyright (C) 1998, 1999, 2000 Free Software Foundation
+/* Copyright (C) 1998, 1999, 2000, 2001 Free Software Foundation
This file is part of libgcj.
@@ -32,13 +32,44 @@
// but it will avoid showing up as a discrepancy when comparing SUIDs.
private static final long serialVersionUID = -6849794470754667710L;
- public static final Comparator CASE_INSENSITIVE_ORDER = new Comparator()
+ /**
+ * An implementation for {@link CASE_INSENSITIVE_ORDER}.
+ * This must be {@link Serializable}.
+ */
+ private static final class CaseInsensitiveComparator
+ implements Comparator, Serializable
{
- public int compare (Object o1, Object o2)
+ /**
+ * The default private constructor generates unnecessary overhead
+ */
+ CaseInsensitiveComparator() {}
+
+ /**
+ * Compares two Strings, using
+ * <code>String.compareToIgnoreCase(String)</code>.
+ *
+ * @param o1 the first string
+ * @param o2 the second string
+ * @return < 0, 0, or > 0 depending on the case-insensitive
+ * comparison of the two strings.
+ * @throws NullPointerException if either argument is null
+ * @throws ClassCastException if either argument is not a String
+ * @see #compareToIgnoreCase(String)
+ */
+ public int compare(Object o1, Object o2)
{
- return ((String) o1).compareToIgnoreCase ((String) o2);
+ return ((String) o1).compareToIgnoreCase((String) o2);
}
- };
+ }
+
+ /**
+ * A Comparator that uses <code>String.compareToIgnoreCase(String)</code>.
+ * This comparator is {@link Serializable}.
+ *
+ * @since 1.2
+ */
+ public static final Comparator CASE_INSENSITIVE_ORDER
+ = new CaseInsensitiveComparator();
public String ()
{